Bug 84338 - [8 Regression] sizeof...() returns always 1 in variadic lambda inside a template
Summary: [8 Regression] sizeof...() returns always 1 in variadic lambda inside a template
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0.1
: P1 normal
Target Milestone: 8.0
Assignee: Jason Merrill
URL:
Keywords: accepts-invalid, rejects-valid, wrong-code
Depends on:
Blocks:
 
Reported: 2018-02-12 14:11 UTC by Benjamin Buch
Modified: 2018-02-13 14:22 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-02-12 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Buch 2018-02-12 14:11:50 UTC
template < typename ... T >
auto f(T ... i){
    [](auto ... i){
        // // wrongly true in current trunk
        // static_assert(sizeof...(i) == 1, "");
        static_assert(sizeof...(i) == 2, "");
    }(i ...);
}

int main(){
    f(0, 1);
}


$ g++ -std=c++14 main.cpp 
main.cpp: In instantiation of 'auto f(T ...) [with T = {int, int}]':
main.cpp:11:11:   required from here
main.cpp:6:36: error: static assertion failed
         static_assert(sizeof...(i) == 2, "");
                       ~~~~~~~~~~~~~^~~~
$ g++ --version
g++ (GCC) 8.0.1 20180212 (experimental)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Known to work in GCC 5 and GCC 6:

$ g++-6 -std=c++14 main.cpp
$ g++-6 --version
g++-6 (Ubuntu/Linaro 6.3.0-18ubuntu2~16.04) 6.3.0 20170519
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++-5 -std=c++14 main.cpp
$ g++-5 --version
g++-5 (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1 20160904
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Comment 1 Jakub Jelinek 2018-02-12 18:31:26 UTC
Started with r251433.
Comment 2 Jason Merrill 2018-02-13 14:22:23 UTC
Fixed.
Comment 3 Jason Merrill 2018-02-13 14:22:34 UTC
Author: jason
Date: Tue Feb 13 14:22:01 2018
New Revision: 257626

URL: https://gcc.gnu.org/viewcvs?rev=257626&root=gcc&view=rev
Log:
	PR c++/84338 - wrong variadic sizeof.

	* pt.c (argument_pack_select_arg): Like the macro, but look through
	a pack expansion.
	(tsubst, tsubst_copy, dependent_template_arg_p): Use it.
	(extract_fnparm_pack): Do make_pack_expansion.
	(extract_locals_r): Do strip a pack expansion.
	* cp-tree.h (ARGUMENT_PACK_SELECT_ARG): Remove.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic13.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/pt.c