[cfe-dev] -Wcatch-incomplete-type-extensions
Eli Friedman
eli.friedman at gmail.com
Wed Jan 18 18:17:47 PST 2012
On Wed, Jan 18, 2012 at 6:01 PM, Howard Hinnant <hhinnant at apple.com> wrote:
> I'm wondering why this is a warning and not an error:
>
> struct A;
>
> void foo();
>
> #include <iostream>
>
> int main()
> {
> try
> {
> foo();
> }
> catch (A&)
> {
> std::cout << "Caught an A\n";
> }
> catch (...)
> {
> std::cout << "Caught ...\n";
> }
> }
>
> struct A {};
>
> void foo()
> {
> throw A();
> }
>
> test.cpp:13:14: warning: ISO C++ forbids catching a reference to incomplete type 'A' [-Wcatch-incomplete-type-extensions]
> catch (A&)
> ^
> test.cpp:1:8: note: forward declaration of 'A'
> struct A;
> ^
> 1 warning generated.
>
> g++-4.2 just says:
>
> test.cpp: In function ‘int main()’:
> test.cpp:13: error: invalid use of incomplete type ‘struct A’
> test.cpp:1: error: forward declaration of ‘struct A’
See http://llvm.org/bugs/show_bug.cgi?id=6527 . Granted, I'm not
really sure that fix was appropriate.
-Eli
More information about the cfe-dev
mailing list