Regression from gcc 3.4.4; under gcc 4.1.1 it produces the diagnostic "error: 'N<int>::okay' is not a valid template argument for type 'bool' because it is a non-constant expression" -- and I am informed (by gdr) that the bug is still present in gcc 4.2.0. The code below makes use of the Boost library; I can also provide the preprocessed version of the same code, if requested, but it's on the order of 1000 lines long: #include "boost/mpl/assert.hpp" template< class T > struct N { static bool const okay = true; BOOST_MPL_ASSERT_MSG( okay, message_goes_here, (T) ); }; int main() { N<int> n; }
Yes we need the preprocessed source. You can attach it to the bug report instead of just copying and pasting it.
Created attachment 12463 [details] preprocessed version of test case
I tried a simple testcase and variations on it (changing (T)(ok) to just ok and such): template <bool a> class b{}; template <class T> class t { static bool const ok = true; b<(T)(ok)> c; }; int main(void) { t<int> a; }
Subject: Re: incorrect " On Thu, 19 Oct 2006, pinskia at gcc dot gnu dot org wrote: | I tried a simple testcase and variations on it (changing (T)(ok) to just ok and | such): yes, the parens don't change anything -- I've tried that. I attempted to reduce the testcase, but I did not have time. My first attempt was too broad and did not reproduce the bug, so I left it to the original form.
Reducing through a nice trick of using delta and using 3.3.x as the base compiler.
Reduced testcase: template< bool C > int assertion_failed( int); template< class > struct N { static bool const okay = true; enum { t = sizeof( assertion_failed<okay>( 0)) }; }; main() { N<int> n; }
Subject: Re: diagnostic on correct code; regression from 3.4.4 On Thu, 19 Oct 2006, pinskia at gcc dot gnu dot org wrote: | Reduced testcase: Very nice. | template< bool C > int assertion_failed( int); | template< class > | struct N | { | static bool const okay = true; | enum { | t = sizeof( assertion_failed<okay>( 0)) | }; | }; | main() missing "int". | { | N<int> n; | }
Note bool has nothing to do with the problem, the following testcase shows that: template< int C > int assertion_failed( int); template< class > struct N { static int const okay = 1; enum { t = sizeof( assertion_failed<okay>( 0)) }; }; int main() { N<int> n; }
(In reply to comment #7) > missing "int". That is because we did not error out on it in 3.3.3 or 3.4.0 for that matter, I wonder why.
Note I found a related regression in 4.0.4 only and I filed that as PR 29522.
*** Bug 29525 has been marked as a duplicate of this bug. ***
From Aleksey Gurtovoy (co-author Boost.MPL): [wrt to this bug] Actually, no, enums in the bug's subject and reduced test case are a red herring. For example, this still fails for me on 4.1.1: template< int C > int assertion_failed(int); template< class > struct N { static int const value = 1; static int const t = sizeof( assertion_failed<value>(0) ); }; int main() { N<int> n; return n.t; } As a matter of fact, my current workaround for this issue involves _introducing_ an auxiliary enum for the values that are used in function templates' non-type arguments, e.g.: template< int C > int assertion_failed(int); template< class > struct N { static int const value = 1; enum { gcc_workaround = value }; static int const t = sizeof( assertion_failed<gcc_workaround>(0) ); // it compiles, yay! };
(In reply to comment #12) > From Aleksey Gurtovoy (co-author Boost.MPL): > [wrt to this bug] > Actually, no, enums in the bug's subject and reduced test case are a > red herring. For example, this still fails for me on 4.1.1: Not really because that passes for me with 4.1.2 and 4.2.0.
Subject: Bug 29518 Author: mmitchel Date: Mon Nov 13 17:48:28 2006 New Revision: 118767 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118767 Log: PR c++/29518 * pt.c (coerce_template_parms): Do not skip_evaluation while substituting template arguments. PR c++/29518 * g++.dg/template/static28.C: New test. Added: trunk/gcc/testsuite/g++.dg/template/static28.C Modified: trunk/gcc/cp/pt.c
Subject: Bug 29518 Author: mmitchel Date: Mon Nov 13 17:49:43 2006 New Revision: 118768 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118768 Log: PR c++/29518 * pt.c (coerce_template_parms): Do not skip_evaluation while substituting template arguments. PR c++/29518 * g++.dg/template/static28.C: New test. Modified: trunk/gcc/cp/ChangeLog trunk/gcc/testsuite/ChangeLog
Fixed in 4.3.0.
Subject: Bug 29518 Author: mmitchel Date: Mon Nov 13 18:41:26 2006 New Revision: 118770 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118770 Log: PR c++/29518 * pt.c (coerce_template_parms): Do not skip_evaluation while substituting template arguments. PR c++/29518 * g++.dg/template/static28.C: New test. Added: branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/static28.C Modified: branches/gcc-4_1-branch/gcc/cp/ChangeLog branches/gcc-4_1-branch/gcc/cp/pt.c branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
Subject: Bug 29518 Author: mmitchel Date: Tue Nov 14 04:59:48 2006 New Revision: 118801 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118801 Log: PR c++/29518 * pt.c (coerce_template_parms): Do not skip_evaluation while substituting template arguments. PR c++/29518 * g++.dg/template/static28.C: New test. Added: branches/gcc-4_2-branch/gcc/testsuite/g++.dg/template/static28.C Modified: branches/gcc-4_2-branch/gcc/cp/ChangeLog branches/gcc-4_2-branch/gcc/cp/pt.c branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
Fixed in 4.1.2, 4.2.0.
*** Bug 29701 has been marked as a duplicate of this bug. ***
Fixed in GCC-4.1.2.