Misleading error if the type in catch() is ambiguous

Peter A. Felvegi petschy@praire-chicken.com
Tue Dec 20 13:31:00 GMT 2011


Dear All,

I suspect there is a regression from g++ 4.4 in later versions. If the 
name of the class is ambiguous in a catch(), this fact is not reported.

I had checked bz, but not found this particular case:
http://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=ambiguous

Attached a simple test case. The lines of the errors are:
31: ambiguous parent class
37: ambiguous type name for variable
43: ambiguous type name for caught exception

I tested on an amd64 machine with Debian Wheezy, stock gcc-4.4, 4.5, 4.6 
and 4.7 built from the svn trunk:

$g++-4.4 -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.6-14' 
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs 
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr 
--program-suffix=-4.4 --enable-shared --enable-linker-build-id 
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext 
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 
--libdir=/usr/lib --enable-nls --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu 
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.6 (Debian 4.4.6-14)

$g++-4.4 -c test_gccexbug.cpp
test_gccexbug.cpp:31: error: reference to ‘ex2’ is ambiguous
test_gccexbug.cpp:17: error: candidates are: class ex2
test_gccexbug.cpp:11: error:                 class t::ex2
test_gccexbug.cpp:31: error: reference to ‘ex2’ is ambiguous
test_gccexbug.cpp:17: error: candidates are: class ex2
test_gccexbug.cpp:11: error:                 class t::ex2
test_gccexbug.cpp: In function ‘void bar()’:
test_gccexbug.cpp:37: error: reference to ‘ex2’ is ambiguous
test_gccexbug.cpp:17: error: candidates are: class ex2
test_gccexbug.cpp:11: error:                 class t::ex2
test_gccexbug.cpp:37: error: reference to ‘ex2’ is ambiguous
test_gccexbug.cpp:17: error: candidates are: class ex2
test_gccexbug.cpp:11: error:                 class t::ex2
test_gccexbug.cpp:37: error: expected ‘;’ before ‘x’
test_gccexbug.cpp:43: error: reference to ‘ex2’ is ambiguous
test_gccexbug.cpp:17: error: candidates are: class ex2
test_gccexbug.cpp:11: error:                 class t::ex2
test_gccexbug.cpp:43: error: expected type-specifier before ‘ex2’
test_gccexbug.cpp:43: error: expected ‘)’ before ‘&’ token
test_gccexbug.cpp:43: error: expected ‘{’ before ‘&’ token
test_gccexbug.cpp:43: error: expected primary-expression before ‘)’ token
test_gccexbug.cpp:43: error: expected ‘;’ before ‘)’ token

Note: ambiguity errors are reported twice for lines 31 and 37 and once 
for line 43.

$g++-4.5 -v
Using built-in specs.
COLLECT_GCC=g++-4.5
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.5.3/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.5.3-9' 
--with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs 
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr 
--program-suffix=-4.5 --enable-shared --enable-linker-build-id 
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext 
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.5 
--libdir=/usr/lib --enable-nls --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin 
--enable-gold --enable-ld=default --with-plugin-ld=ld.gold 
--enable-objc-gc --with-arch-32=i586 --with-tune=generic 
--enable-checking=release --build=x86_64-linux-gnu 
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.5.3 (Debian 4.5.3-9)

$g++-4.5 -c test_gccexbug.cpp
test_gccexbug.cpp:31:27: error: reference to ‘ex2’ is ambiguous
test_gccexbug.cpp:17:1: error: candidates are: class ex2
test_gccexbug.cpp:11:1: error:                 class t::ex2
test_gccexbug.cpp: In function ‘void bar()’:
test_gccexbug.cpp:37:7: error: reference to ‘ex2’ is ambiguous
test_gccexbug.cpp:17:1: error: candidates are: class ex2
test_gccexbug.cpp:11:1: error:                 class t::ex2
test_gccexbug.cpp:37:11: error: expected ‘;’ before ‘x’
test_gccexbug.cpp:43:17: error: expected type-specifier before ‘ex2’
test_gccexbug.cpp:43:20: error: expected ‘)’ before ‘&’ token
test_gccexbug.cpp:43:20: error: expected ‘{’ before ‘&’ token
test_gccexbug.cpp:43:21: error: expected primary-expression before ‘)’ token
test_gccexbug.cpp:43:21: error: expected ‘;’ before ‘)’ token

Note: ambiguity is reported once for lines 31 and 37, and no ambiguity 
is reported for line 43. The error is misleading imho, because it 
suggests that the type name is not know instead of being ambiguous.

I suspect that the fix that removed the duplicate ambiguity messages 
might have gone a bit too far in the case of the catch(), though I 
couldn't check this since I'm not familiar with the gcc source.

gcc-4.6 and gcc-4.7 (built from the svn trunk, r182460) give the same 
error as gcc-4.5 above.

Regards, Peter

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_gccexbug.cpp
Type: text/x-c++src
Size: 716 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20111220/d92269ad/attachment.bin>


More information about the Gcc mailing list