Bug 89874

Summary: invalid conversion accepted in decltype in a template
Product: gcc Reporter: Martin Sebor <msebor>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal Keywords: accepts-invalid
Priority: P3    
Version: 9.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47488
Host: Target:
Build: Known to work:
Known to fail: 4.1.3, 4.3.5, 4.4.7, 4.8.5, 4.9.4, 5.4.0, 6.4.0, 7.3.0, 8.3.0, 9.0 Last reconfirmed:

Description Martin Sebor 2019-03-28 20:41:14 UTC
G++ accepts the following ill-formed program:

$ cat u.C && /gcc -S -Wall -Wextra u.C
char f (int);

template <typename T>
decltype (f ("123"))   // invalid: no conversion from const char* to int
g (T);

void h () { g (0); }

Clang prints:

u.C:4:11: error: no matching function for call to 'f'
decltype (f ("123"))   // invalid: no conversion from const char* to int
          ^
u.C:1:6: note: candidate function not viable: no known conversion from
      'const char [4]' to 'int' for 1st argument
char f (int);
     ^
u.C:7:13: error: no matching function for call to 'g'
void h () { g (0); }
            ^
2 errors generated.
Comment 1 Martin Sebor 2019-03-28 20:46:32 UTC
This was never rejected going as far back as GCC 4.1.

*** This bug has been marked as a duplicate of bug 57943 ***
Comment 2 Martin Sebor 2019-03-28 21:50:32 UTC
See pr47488 for the origin of the test case.