Bug 43831 - [C++0x] gcc-4.5.0 does not fail invalid lambda captures (against n3092 5.1.2/8)
Summary: [C++0x] gcc-4.5.0 does not fail invalid lambda captures (against n3092 5.1.2/8)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.7.0
Assignee: Jason Merrill
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2010-04-21 13:40 UTC by Paul Bibbings
Modified: 2021-12-17 03:51 UTC (History)
3 users (show)

See Also:
Host: i686-pc-cygwin
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-04-21 19:04:56


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Bibbings 2010-04-21 13:40:00 UTC
The following code reproduces the Example in n3092 (FCD) 5.1.2/8, complete with the comments given there:

14:36:12 Paul Bibbings@JIJOU
/cygdrive/d/CPPProjects/nano/gcc_bugs $cat _5_1_2_8.cpp
// file: _5_1_2_8.cpp

struct S2 { void f(int i); };
void S2::f(int i) {
   [&, i]{ };     // OK
   [&, &i]{ };    // error: i preceded by & when & is the default
   [=, this]{ };  // error: this when = is the default
   // [i, i]{ };     // error: i repeated
}



The fourth lambda-expression has been commented out to reflect the fact that gcc-4.5.0 correctly handles this as an error.  The second and third - which should be errors according 5.1.2/8 - are left uncommented.  gcc-4.5.0 compiles this code without issuing an error, thus not handling the following from 5.1.2/8 correctly:
   - "If a lambda-capture includes a capture-default that is &, the identifiers in the lambda capture shall not be preceded by &"; and
   - "If a lambda-capture includes a capture-default that is =, the lambda capture shall not contain this."


14:33:29 Paul Bibbings@JIJOU
/cygdrive/d/CPPProjects/nano/gcc_bugs $make
i686-pc-cygwin-gcc-4.5.0 -v -save-temps -Wall -std=c++0x -pedantic -c _5_1_2_8.cpp
Using built-in specs.
COLLECT_GCC=i686-pc-cygwin-gcc-4.5.0
COLLECT_LTO_WRAPPER=/opt/gcc-4.5.0/libexec/gcc/i686-pc-cygwin/4.5.0/lto-wrapper.exe
Target: i686-pc-cygwin
Configured with: ./configure --prefix=/opt/gcc-4.5.0 --enable-bootstrap --enable-version-specific-runtime-libs --enable-static --enable-shared --enable-shared-libgcc --disable-__cxa_atexit --with-gnu-ld --with-gnu-as --with-dwarf2 --disable-sjlj-exceptions --enable-languages=c,c++ --disable-symvers --enable-libgomp --enable-libssp --enable-threads=posix --with-arch-i686 --with-tune=generic
Thread model: posix
gcc version 4.5.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-std=c++0x' '-pedantic' '-c' '-mtune=generic' '-march=pentiumpro'
 /opt/gcc-4.5.0/libexec/gcc/i686-pc-cygwin/4.5.0/cc1plus.exe -E -quiet -v -D__CYGWIN32__ -D__CYGWIN__ -Dunix -D__unix__ -D__unix -idirafter /usr/lib/../include/w32api -idirafter ../../include/w32api _5_1_2_8.cpp -mtune=generic -march=pentiumpro -std=c++0x -Wall -pedantic -fpch-preprocess -o _5_1_2_8.ii
ignoring nonexistent directory "/opt/gcc-4.5.0/lib/gcc/i686-pc-cygwin/4.5.0/../../../../i686-pc-cygwin/include"
ignoring nonexistent directory "../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
 /opt/gcc-4.5.0/lib/gcc/i686-pc-cygwin/4.5.0/include/c++
 /opt/gcc-4.5.0/lib/gcc/i686-pc-cygwin/4.5.0/include/c++/i686-pc-cygwin
 /opt/gcc-4.5.0/lib/gcc/i686-pc-cygwin/4.5.0/include/c++/backward
 /usr/local/include
 /opt/gcc-4.5.0/include
 /opt/gcc-4.5.0/lib/gcc/i686-pc-cygwin/4.5.0/include
 /opt/gcc-4.5.0/lib/gcc/i686-pc-cygwin/4.5.0/include-fixed
 /usr/include
 /usr/lib/../include/w32api
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-std=c++0x' '-pedantic' '-c' '-mtune=generic' '-march=pentiumpro'
 /opt/gcc-4.5.0/libexec/gcc/i686-pc-cygwin/4.5.0/cc1plus.exe -fpreprocessed _5_1_2_8.ii -quiet -dumpbase _5_1_2_8.cpp -mtune=generic -march=pentiumpro -auxbase _5_1_2_8 -Wall -pedantic -std=c++0x -version -o _5_1_2_8.s
GNU C++ (GCC) version 4.5.0 (i686-pc-cygwin)
        compiled by GNU C version 4.5.0, GMP version 4.3.2, MPFR version 2.4.1, MPC version 0.8.1
warning: GMP header version 4.3.2 differs from library version 4.3.1.
warning: MPFR header version 2.4.1 differs from library version 2.4.1-p5.
warning: MPC header version 0.8.1 differs from library version 0.8.
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129712
GNU C++ (GCC) version 4.5.0 (i686-pc-cygwin)
        compiled by GNU C version 4.5.0, GMP version 4.3.2, MPFR version 2.4.1, MPC version 0.8.1
warning: GMP header version 4.3.2 differs from library version 4.3.1.
warning: MPFR header version 2.4.1 differs from library version 2.4.1-p5.
warning: MPC header version 0.8.1 differs from library version 0.8.
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129712
Compiler executable checksum: 81a7a49c1fa28713ff621b6b856147c0
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-std=c++0x' '-pedantic' '-c' '-mtune=generic' '-march=pentiumpro'
 as -v -o _5_1_2_8.o _5_1_2_8.s
GNU assembler version 2.20.51 (i686-cygwin) using BFD version (GNU Binutils) 2.20.51.20100410
COMPILER_PATH=/opt/gcc-4.5.0/libexec/gcc/i686-pc-cygwin/4.5.0/:/opt/gcc-4.5.0/libexec/gcc/i686-pc-cygwin/4.5.0/:/opt/gcc-4.5.0/libexec/gcc/i686-pc-cygwin/:/opt/gcc-4.5.0/lib/gcc/i686-pc-cygwin/4.5.0/:/opt/gcc-4.5.0/lib/gcc/i686-pc-cygwin/
LIBRARY_PATH=/opt/gcc-4.5.0/lib/gcc/i686-pc-cygwin/4.5.0/:/opt/gcc-4.5.0/lib/gcc/i686-pc-cygwin/4.5.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-std=c++0x' '-pedantic' '-c' '-mtune=generic' '-march=pentiumpro'

14:33:31 Paul Bibbings@JIJOU
/cygdrive/d/CPPProjects/nano/gcc_bugs $


14:36:04 Paul Bibbings@JIJOU
/cygdrive/d/CPPProjects/nano/gcc_bugs $cat _5_1_2_8.ii
# 1 "_5_1_2_8.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "_5_1_2_8.cpp"


struct S2 { void f(int i); };
void S2::f(int i) {
   [&, i]{ };
   [&, &i]{ };
   [=, this]{ };

}
Comment 1 Jason Merrill 2011-06-20 14:39:48 UTC
Author: jason
Date: Mon Jun 20 14:39:44 2011
New Revision: 175211

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175211
Log:
	PR c++/43831
	* parser.c (cp_parser_lambda_introducer): Complain about redundant
	captures.
	* semantics.c (add_capture): Likewise.
	(register_capture_members): Clear IDENTIFIER_MARKED.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-capture-redundancy.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 Jason Merrill 2011-06-20 14:55:05 UTC
Fixed for 4.7.0.