User account creation filtered due to spam.

Bug 53531 - <,,,,> accepted as template arguments for variadic template
Summary: <,,,,> accepted as template arguments for variadic template
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Jonathan Wakely
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2012-05-30 16:22 UTC by Jonathan Wakely
Modified: 2012-07-13 07:54 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.6.3, 4.7.1
Last reconfirmed: 2012-07-10 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2012-05-30 16:22:42 UTC
template <typename ...> struct S;

int i = S<,,,,>::undefined;
Comment 1 Niels Penneman 2012-07-10 10:37:34 UTC
Exactly the same behavior with both 4.6.3 and 4.7.1

Similar test case below. Adding a trailing comma to a list of template arguments breaks the code but compiles successfully and without warnings. A trailing comma in a template list of for instance boost::mpl::vector will make the vector "empty".

#########################
template <typename ... Ts>
struct S;

template <typename T, typename ... Ts>
struct S<T, Ts ...> { static constexpr int count = S<Ts ...>::count + 1; };

template <typename T>
struct S<T>         { static constexpr int count = 1; };

int main()
{
  return S<char, int, long,>::count;
}
#########################
$ g++ -v
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.3/g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.6.3/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.6.3/work/gcc-4.6.3/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.3 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.3 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.3/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.3/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --with-ppl --with-cloog --disable-ppl-version-check --with-cloog-include=/usr/include/cloog-ppl --enable-lto --enable-nls --without-included-gettext --with-system-zlib --enable-obsolete --disable-werror --enable-secureplt --enable-multilib --disable-libmudflap --disable-libssp --enable-libgomp --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.6.3/python --enable-checking=release --disable-libgcj --disable-libquadmath --enable-languages=c,c++ --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-targets=all --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.6.3 p1.3, pie-0.5.2'
Thread model: posix
gcc version 4.6.3 (Gentoo 4.6.3 p1.3, pie-0.5.2) 

$ g++ -v
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.1/g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.7.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.7.1/work/gcc-4.7.1/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.1 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.1 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.1/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.1/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --with-ppl --with-cloog --disable-ppl-version-check --with-cloog-include=/usr/include/cloog-ppl --enable-lto --enable-nls --without-included-gettext --with-system-zlib --enable-obsolete --disable-werror --enable-secureplt --enable-multilib --with-multilib-list=m32,m64 --disable-libmudflap --disable-libssp --enable-libgomp --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.7.1/python --enable-checking=release --disable-libgcj --disable-libquadmath --enable-languages=c,c++ --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.1 p1.0, pie-0.5.3'
Thread model: posix
gcc version 4.7.1 (Gentoo 4.7.1 p1.0, pie-0.5.3) 
#########################

Command: g++ -Wall -Wextra -std=c++0x undef.cpp
Output: none, completes succesfully

Command: ./a.out ; echo $?
Output: 0

When omitting the trailing comma, return status of compiled application is 3 as expected.
Comment 2 Jonathan Wakely 2012-07-10 11:01:40 UTC
It's now rejected on trunk:

c.cc:3:15: error: template argument 1 is invalid
 int i = S<,,,,>::undefined;
               ^
c.cc:3:15: error: template argument 2 is invalid
c.cc:3:15: error: template argument 3 is invalid
c.cc:3:15: error: template argument 4 is invalid
c.cc:3:15: error: template argument 5 is invalid

(I might have been using an older 4.8 snapshot when I reported the bug, not sure now.)

Jason, any idea which patch fixed these cases and if we need anything in the testsuite to prevent regressions before closing it?
Comment 3 Jason Merrill 2012-07-10 12:58:25 UTC
(In reply to comment #2)
> Jason, any idea which patch fixed these cases and if we need anything in the
> testsuite to prevent regressions before closing it?

Nothing springs to mind.  grep ,, variadic* doesn't get any hits, so adding a testcase wouldn't hurt.
Comment 4 Jonathan Wakely 2012-07-10 13:03:09 UTC
OK, thanks, I'll do that.

I tried reverting the patch for PR 47220 but that wasn't it, and I didn't look any further.
Comment 5 Jonathan Wakely 2012-07-13 07:53:21 UTC
Author: redi
Date: Fri Jul 13 07:53:12 2012
New Revision: 189452

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189452
Log:
	PR c++/53531
	* testsuite/g++.dg/cpp0x/variadic135.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/variadic135.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 6 Jonathan Wakely 2012-07-13 07:54:37 UTC
Fixed on trunk