1

I have the following code

#include <tuple>

struct A{
    int a;
    int b;
};

std::tuple<A,bool> get(){
    return {{}, true};
}

With GCC 9.* and GCC 10., everything works fine. But when compiling with GCC 11., it compiles failed with following error message

<source>: In function 'std::tuple<A, bool> get()':
<source>:10:21: error: conversion from '<brace-enclosed initializer list>' to 'std::tuple<A, bool>' is ambiguous
   10 |     return {{}, true};
      |                     ^
In file included from <source>:2:
/opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/tuple:1159:9: note: candidate: 'std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&) [with _Alloc = bool; typename std::enable_if<std::_TupleConstraints<std::is_object<_Alloc>::value, _T1, _T2>::__is_implicitly_default_constructible(), bool>::type <anonymous> = true; _T1 = A; _T2 = bool]'
 1159 |         tuple(allocator_arg_t __tag, const _Alloc& __a)
      |         ^~~~~
/opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/tuple:1067:9: note: candidate: 'constexpr std::tuple<_T1, _T2>::tuple(const _T1&, const _T2&) [with bool _Dummy = true; typename std::enable_if<std::_TupleConstraints<_Dummy, _T1, _T2>::__is_implicitly_constructible<const _T1&, const _T2&>(), bool>::type <anonymous> = true; _T1 = A; _T2 = bool]'
 1067 |         tuple(const _T1& __a1, const _T2& __a2)
      |         ^~~~~
Compiler returned: 1

I noticed that both candinates exist in every version of GCC. So why would compiling failed in GCC 11? What makes this change.

GCC 10.3: https://godbolt.org/z/dbfv68xcr

GCC 11.3: https://godbolt.org/z/M3M7zesWf

==== UPDATE ====

Actually I understand why this code causes compiling fail. But why do GCC 10.* and its ancestors compile?

cigien
  • 57,834
  • 11
  • 73
  • 112
Kidsunbo
  • 1,024
  • 1
  • 11
  • 21

1 Answers1

0

OK... I might find the answer.

Non-type template parameter can be class type right now, so GCC allows it while previous GCC grammer does not. Maybe this is the reason why both candinates are valid and cause ambiguous.

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2450

Kidsunbo
  • 1,024
  • 1
  • 11
  • 21