[Bug c++/97174] out-of-namespace function definition

2020-09-23 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97174

Jonathan Wakely  changed:

   What|Removed |Added

   Severity|normal  |enhancement

--- Comment #3 from Jonathan Wakely  ---
Right, the redefinition is dependent and we don't check it until instantiation.
That's allowed by the standard.

Reduced:

template struct make_dependent { using type = T; };
template using make_dependent_t = typename make_dependent::type;

namespace N {
template 
make_dependent_t conv (T);
}

template 
long N::conv (T val)
{ return static_cast(val); }


Or simply:


template struct make_dependent { using type = T; };
template using make_dependent_t = typename make_dependent::type;

template 
make_dependent_t conv (T);

template 
long ::conv (T val)
{ return static_cast(val); }

[Bug c++/97174] out-of-namespace function definition

2020-09-23 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97174

--- Comment #2 from Richard Biener  ---
With an instantiation added:

int main () { N::conv (1); }

we get

t.C: In function 'int main()':
t.C:13:25: error: call of overloaded 'conv(int)' is ambiguous
   13 | int main () { N::conv (1); }
  | ^
t.C:6:36: note: candidate: 'std::make_unsigned_t N::conv(T) [with T = int;
std::make_unsigned_t = unsigned int]'
6 |   typename std::make_unsigned_t conv (T);
  |^~~~
t.C:10:6: note: candidate: 'long int N::conv(T) [with T = int]'
   10 | long N::conv (T val)
  |  ^

eventually no diagnostic is required for the template definition.

[Bug c++/97174] out-of-namespace function definition

2020-09-23 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97174

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
  Known to fail||10.2.1, 7.5.0
   Keywords||accepts-invalid
   Last reconfirmed||2020-09-23
 Ever confirmed|0   |1

--- Comment #1 from Richard Biener  ---
Confirmed.  clang rejects it with

t.C:10:9: error: out-of-line definition of 'conv' does not match any
declaration in namespace 'N'
long N::conv (T val)
^~~~