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

Harald van Dijk <harald at gigawatt dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |harald at gigawatt dot nl

--- Comment #11 from Harald van Dijk <harald at gigawatt dot nl> ---
GCC and clang are instantiating constexpr function bodies when only the
signature should be checked (when they appear in unevaluated expressions). A
shorter example program:

template <typename T> constexpr int f(T t) { return t; }
int main() { sizeof(f("")); }

This is rejected by GCC and clang, but accepted by Intel and Sun C++. As far as
I can tell, it should be accepted. f is used in a context where a definition of
f is not required, so f should not be instantiated. f is used in a way that
involves overload resolution, so a declaration of f is instantiated, but that
declaration does not contain the error that GCC and clang report.

GCC and clang accept it when constexpr is removed.

It's made worse by the fact that it happens even in SFINAE contexts, where such
an error should at worst lead to a substitution failure:

template <typename T> constexpr int f(T t) { return t; }
template <typename T, typename = decltype(f(T()))> void g(T) { }
void g(...) { }
int main() { g(""); }

Here, either the use of f(T()) is an error, so overload resolution should
discard the first g overload, and the program should be accepted, or the use of
f(T()) is valid, so overload resolution should prefer the first g overload, and
the program should still be accepted. But even this is rejected by GCC and
clang.

Even if this gets worked around in libstdc++, it's probably worth tracking this
as a C++ frontend bug as well.

The programs in my comment here are accepted by G++ 4.5.4 (with -std=c++0x),
and rejected by 4.6.4 and later.

Reply via email to