Bug 52595 - [DR 325] commas and non-static data member initializers don't mix
Summary: [DR 325] commas and non-static data member initializers don't mix
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 6.0
Assignee: Nathan Sidwell
URL:
Keywords:
: 61290 61690 65110 65514 66344 66961 69809 78011 80890 (view as bug list)
Depends on: C++DR325
Blocks: NSDMI
  Show dependency treegraph
 
Reported: 2012-03-15 18:47 UTC by Jeremy Maitin-Shepard
Modified: 2024-08-08 04:27 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-03-15 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeremy Maitin-Shepard 2012-03-15 18:47:36 UTC
With this example:

---

template <class T, int N>
struct A {
  static int foo();
};


template <class T, int N>
struct B {
  int var = A<T,N>::foo();
};

---

Compiled with -std=gnu++11, g++ gives the following error:

test.cpp:9:17: error: expected ';' at end of member declaration
test.cpp:9:17: error: declaration of 'int B<T, N>::N'
test.cpp:7:20: error:  shadows template parm 'int N'
test.cpp:9:18: error: expected unqualified-id before '>' token
test.cpp:9:15: error: wrong number of template arguments (1, should be 2)
test.cpp:2:8: error: provided for 'template<class T, int N> struct A'

Surrounding the initializer in parentheses, i.e.

  int var = (A<T,N>::foo());

fixes the error.  This error also does not happen for static data members.

It appears that g++ is not properly parsing the comma inside the template argument list.

COLLECT_GCC=g++-4.7.0-pre9999
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.7.0-pre9999/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.7.0_pre9999/work/gcc-4.7.0-9999/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.0-pre9999 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0-pre9999/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.0-pre9999 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.0-pre9999/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.0-pre9999/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0-pre9999/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --enable-lto --disable-nls --with-system-zlib --disable-werror --enable-secureplt --enable-multilib --with-multilib-list=m32,m64 --enable-libmudflap --disable-libssp --enable-libgomp --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.7.0-pre9999/python --enable-checking=release --disable-libgcj --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-targets=all --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.7.0_pre9999'
Thread model: posix
gcc version 4.7.0-pre9999 20120314 (prerelease) commit fe9f13b8d6563daf45c0ed10da40ec2c05473a11 (Gentoo 4.7.0_pre9999)
Comment 1 Andrew Pinski 2012-03-15 18:53:00 UTC
See C++ defect report 325, it says it applies to NSDMI also.
Comment 2 Andrew Pinski 2012-03-15 18:56:36 UTC
http://open-std.org/JTC1/SC22/WG21/docs/cwg_active.html#325 for future reference.
Comment 3 Paolo Carlini 2012-03-20 11:29:49 UTC
I'm a bit confused here. If this is Core/325 should be duplicate of PR51666, right? But, maybe too quickly, I closed the latter as fixed upon Jason commit (see also http://gcc.gnu.org/ml/gcc-patches/2012-01/msg00062.html).

So, what's going on? Was the commit for PR51666 incomplete, so to speak?
Comment 4 Andrew Pinski 2012-03-20 23:00:19 UTC
(In reply to comment #3)
> So, what's going on? Was the commit for PR51666 incomplete, so to speak?

Maybe it was incomplete but then again the Defect report is still open though there has been some changes to the dr about the change and such.
Comment 5 Jonathan Wakely 2014-05-23 11:09:15 UTC
*** Bug 61290 has been marked as a duplicate of this bug. ***
Comment 6 Jonathan Wakely 2014-07-04 08:29:17 UTC
*** Bug 61690 has been marked as a duplicate of this bug. ***
Comment 7 Jonathan Wakely 2015-02-18 19:30:01 UTC
*** Bug 65110 has been marked as a duplicate of this bug. ***
Comment 8 Jonathan Wakely 2015-03-22 15:02:11 UTC
*** Bug 65514 has been marked as a duplicate of this bug. ***
Comment 9 Jonathan Wakely 2015-05-30 16:04:27 UTC
*** Bug 66344 has been marked as a duplicate of this bug. ***
Comment 10 Nathan Sidwell 2015-06-05 13:36:02 UTC
Author: nathan
Date: Fri Jun  5 13:35:30 2015
New Revision: 224152

URL: https://gcc.gnu.org/viewcvs?rev=224152&root=gcc&view=rev
Log:
	cp/
	PR c++/52595
	* parser.c (cp_parser_cache_defarg): Continue looking for
	declarators when scanning a potential template argument list of an
	NSDMI.

	testsuite/
	PR c++/52595
	* g++,dg/cpp0x/nsdmi-defer5.C: Add template case.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer5.C
Comment 11 Nathan Sidwell 2015-06-05 14:16:43 UTC
patch committed

https://gcc.gnu.org/ml/gcc-patches/2015-05/msg02582.html
Comment 12 Jonathan Wakely 2015-07-21 18:20:40 UTC
*** Bug 66961 has been marked as a duplicate of this bug. ***
Comment 13 Jonathan Wakely 2016-02-14 19:57:30 UTC
*** Bug 69809 has been marked as a duplicate of this bug. ***
Comment 14 Andrew Pinski 2016-10-18 05:16:52 UTC
*** Bug 78011 has been marked as a duplicate of this bug. ***
Comment 15 Jonathan Wakely 2017-05-26 16:53:31 UTC
*** Bug 80890 has been marked as a duplicate of this bug. ***