Prior to version 4.6, GCC accepted the well-formed program below. Since r166453 GCC rejects it because it fails to eliminate the second overload of the foo template from the overload list. The second overload isn't viable because substituting int for T results in the second argument to the function having an invalid type (pointer to an array of excessive size). $ cat y.C && gcc -S -Wall -Wextra -Wpedantic y.C template <class T> int foo (T); template <class T, class U = T [sizeof (T) - 5]> int foo (T, U* = 0); int i = foo (123); y.C:7:17: error: call of overloaded ‘foo(int)’ is ambiguous int i = foo (123); ^ y.C:2:5: note: candidate: int foo(T) [with T = int] int foo (T); ^~~ y.C:5:5: note: candidate: int foo(T, U*) [with T = int; U = int [-1]] int foo (T, U* = 0); ^~~ Conversely, while prior to r166453 GCC would reject the following invalid program template <class T> int foo (T, int (*)[sizeof (T) - 5] = 0); int i = foo (123); with t.C:4:17: error: no matching function for call to ‘foo(int)’ t.C:2:40: note: candidate is: template<class T> int foo(T, int (*)[(sizeof (T) - 5)]) GCC 4.6 and later accept it.
Redoing lost comments: https://gcc.gnu.org/ml/gcc-bugs/2017-08/msg01610.html Eric Gallager <egallager at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2017-08-14 CC| |egallager at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #1 from Eric Gallager <egallager at gcc dot gnu.org> --- Confirmed that gcc rejects the former and accepts the latter, although the former should probably still get a warning anyways even if it's not supposed to error, just for being confusing (in my biased-against-c++-things-like-overloading opinion) https://gcc.gnu.org/ml/gcc-bugs/2017-08/msg01626.html --- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> --- Idiomatic C++ code should not warn. Clang and ICC accept the former and reject the latter. VC++ rejects both, which is odd.
GCC 5 branch is being closed
Author: jason Date: Fri Mar 16 18:56:01 2018 New Revision: 258604 URL: https://gcc.gnu.org/viewcvs?rev=258604&root=gcc&view=rev Log: PR c++/80227 - SFINAE and negative array size. * decl.c (compute_array_index_type): Use build_converted_constant_expr and valid_constant_size_p. Added: trunk/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg8.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c trunk/gcc/testsuite/g++.dg/gomp/pr47963.C trunk/gcc/testsuite/g++.dg/init/new37.C trunk/gcc/testsuite/g++.dg/init/new44.C trunk/gcc/testsuite/g++.dg/ubsan/pr81530.C
Author: jason Date: Fri Mar 23 14:39:47 2018 New Revision: 258811 URL: https://gcc.gnu.org/viewcvs?rev=258811&root=gcc&view=rev Log: PR c++/80227 - SFINAE and negative array size. * decl.c (compute_array_index_type): Convert to signed for negative check. Added: branches/gcc-7-branch/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg8.C Modified: branches/gcc-7-branch/gcc/cp/ChangeLog branches/gcc-7-branch/gcc/cp/decl.c branches/gcc-7-branch/gcc/testsuite/g++.dg/init/new44.C
Fixed for 7.4/8.
*** Bug 82893 has been marked as a duplicate of this bug. ***
*** Bug 68280 has been marked as a duplicate of this bug. ***
*** Bug 80169 has been marked as a duplicate of this bug. ***