http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49834

           Summary: type deduction in for-each loop in template function
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: lex4...@gmail.com


Created attachment 24822
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24822
example source that produces the bug

As I suppose auto keyword should be replaced by type of the expression,
for example consider the expression where p has C type, C is STL iterable type:
"for (const auto &i: p)". Here 'auto' should be replaced with C::value_type.
But in attached source I have two similar loops: "for (const C::value_type &i:
p) i.second.get_value<int>()" and "for (const auto &i: p)
i.second.get_value<int>()" where first is compiled but second has compilation
error:
"
test.cpp: In function 'Ret f(const C&)':
test.cpp:32:22: error: expected primary-expression before 'int'
test.cpp:32:22: error: expected ';' before 'int'
"

this behaviour is the same on system 4.6.1 gcc version, I also used
gcc-snapshot 4.7.20110723-1 as g++-4.7

# uname -a
Linux LeX-laptop 2.6.38-ARCH #1 SMP PREEMPT Mon Jun 6 22:49:29 CEST 2011 x86_64
Genuine Intel(R) CPU U4100 @ 1.30GHz GenuineIntel GNU/Linux

# some system info
I am running amd64 Archlinux

Full error message with
# LANG=C g++-4.7 -v -std=c++0x test.cpp -Wall -Wextra

Using built-in specs.
COLLECT_GCC=g++-4.7
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with:
/usr/src/builder/yaourt/yaourt-tmp-lex/aur-gcc-snapshot/src/gcc-4.7-20110723/configure
--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --datadir=/usr/share/gcc-4.7
--with-bugurl='http://aur.archlinux.org/packages.php?ID=16045'
--enable-languages=c,c++,lto --enable-shared --enable-threads=posix
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-clocale=gnu --enable-gnu-unique-object --enable-linker-build-id
--with-ppl --enable-cloog-backend=isl --enable-lto --enable-gold
--enable-ld=default --enable-plugin --with-plugin-ld=ld.gold
--with-linker-hash-style=gnu --disable-multilib --disable-libstdcxx-pch
--enable-checking=release --disable-werror --program-suffix=-4.7
--enable-version-specific-runtime-libs
Thread model: posix
gcc version 4.7.0 20110723 (experimental) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-std=c++0x' '-Wall' '-Wextra' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/cc1plus -quiet -v -D_GNU_SOURCE
test.cpp -quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test
-Wall -Wextra -std=c++0x -version -o /tmp/cc0WblC2.s
GNU C++ (GCC) version 4.7.0 20110723 (experimental) (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.7.0 20110723 (experimental), GMP version
5.0.2, MPFR version 3.0.1-p4, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/include/c++

/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/include/c++/x86_64-unknown-linux-gnu
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/include/c++/backward
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/include
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.7.0 20110723 (experimental) (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.7.0 20110723 (experimental), GMP version
5.0.2, MPFR version 3.0.1-p4, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 914976d5d676edf344087969a3789281
test.cpp: In function 'Ret f(const C&)':
test.cpp:32:22: error: expected primary-expression before 'int'
test.cpp:32:22: error: expected ';' before 'int'

Reply via email to