https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116011

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Clang also rejects this:
```
<source>:13:55: error: no matching function for call to 'f'
   13 | constexpr int g(char (*p)[sizeof(char)] = 0) { return f<A>(p); }
      |                                                       ^~~~
<source>:8:15: note: candidate function template not viable: no known
conversion from 'char (*)[1]' to 'char (*)[2]' for 1st argument
    8 | constexpr int f(char (*)[sizeof(q(&T::x))]) { return 1; }
      |               ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:11:15: note: candidate function template not viable: no known
conversion from 'char (*)[1]' to 'char (*)[2]' for 1st argument
   11 | constexpr int f(char (*)[sizeof(q(&(T::x)))]) { return 2; }
      |               ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:16:15: error: static assertion expression is not an integral constant
expression
   16 | static_assert(g() == 2);
      |               ^~~~~~~~
```

MSVC rejects it the same way as GCC:
```

<source>(11): error C2995: 'int f(char (*)[])': function template has already
been defined
<source>(8): note: see declaration of 'f'
<source>(13): error C3615: constexpr function 'g' cannot result in a constant
expression
<source>(13): note: failure was caused by control reaching the end of a
constexpr function
<source>(14): error C3615: constexpr function 'h' cannot result in a constant
expression
<source>(14): note: failure was caused by control reaching the end of a
constexpr function
<source>(16): error C2131: expression did not evaluate to a constant
<source>(16): note: function violates 'constexpr' rules or has errors
<source>(16): note: see usage of 'g'
<source>(16): note: the call stack of the evaluation (the oldest call first) is
<source>(16): note: while evaluating function 'int g(char (*)[1])'
<source>(17): error C2131: expression did not evaluate to a constant
<source>(17): note: function violates 'constexpr' rules or has errors
<source>(17): note: see usage of 'h'
<source>(17): note: the call stack of the evaluation (the oldest call first) is
<source>(17): note: while evaluating function 'int h(char (*)[2])'
```

EDG is also rejects it the same way as GCC:
```
"<source>", line 11: error: function template "f" has already been defined
(previous definition at line 7)
  constexpr int f(char (*)[sizeof(q(&(T::x)))]) { return 2; }
                ^

"<source>", line 13: error: no instance of function template "f" matches the
argument list
            argument types are: (char (*)[1])
  constexpr int g(char (*p)[sizeof(char)] = 0) { return f<A>(p); }
                                                        ^
"<source>", line 8: note: function template "f" does not match because argument
#1 does not match parameter
  constexpr int f(char (*)[sizeof(q(&T::x))]) { return 1; }
                ^

"<source>", line 17: error: static assertion failed
  static_assert(h() == 1);
  ^

```

Reply via email to