[cfe-commits] r97927 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp test/SemaCXX/exceptions.cpp test/SemaTemplate/instantiate-function-1.cpp
Douglas Gregor
dgregor at apple.com
Sun Mar 7 17:47:36 PST 2010
Author: dgregor
Date: Sun Mar 7 19:47:36 2010
New Revision: 97927
URL: http://llvm.org/viewvc/llvm-project?rev=97927&view=rev
Log:
Downgrade errors when trying to catch a pointer or reference to
incomplete type to warnings; GCC (and EDG in GCC compatibility mode)
permit such handles. Fixes PR6527.
(For real this time)
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/exceptions.cpp
cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=97927&r1=97926&r2=97927&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Mar 7 19:47:36 2010
@@ -2048,10 +2048,10 @@
def err_decrement_bool : Error<"cannot decrement expression of type bool">;
def warn_increment_bool : Warning<
"incrementing expression of type bool is deprecated">, InGroup<Deprecated>;
-def err_catch_incomplete_ptr : Error<
- "cannot catch pointer to incomplete type %0">;
-def err_catch_incomplete_ref : Error<
- "cannot catch reference to incomplete type %0">;
+def ext_catch_incomplete_ptr : ExtWarn<
+ "ISO C++ forbids catching a pointer to incomplete type %0">;
+def ext_catch_incomplete_ref : ExtWarn<
+ "ISO C++ forbids catching a reference to incomplete type %0">;
def err_catch_incomplete : Error<"cannot catch incomplete type %0">;
def err_catch_rvalue_ref : Error<"cannot catch exceptions by rvalue reference">;
def err_qualified_catch_declarator : Error<
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=97927&r1=97926&r2=97927&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sun Mar 7 19:47:36 2010
@@ -5195,21 +5195,28 @@
Invalid = true;
}
+ // GCC allows catching pointers and references to incomplete types
+ // as an extension; so do we, but we warn by default.
+
QualType BaseType = ExDeclType;
int Mode = 0; // 0 for direct type, 1 for pointer, 2 for reference
unsigned DK = diag::err_catch_incomplete;
+ bool IncompleteCatchIsInvalid = true;
if (const PointerType *Ptr = BaseType->getAs<PointerType>()) {
BaseType = Ptr->getPointeeType();
Mode = 1;
- DK = diag::err_catch_incomplete_ptr;
+ DK = diag::ext_catch_incomplete_ptr;
+ IncompleteCatchIsInvalid = false;
} else if (const ReferenceType *Ref = BaseType->getAs<ReferenceType>()) {
// For the purpose of error recovery, we treat rvalue refs like lvalue refs.
BaseType = Ref->getPointeeType();
Mode = 2;
- DK = diag::err_catch_incomplete_ref;
+ DK = diag::ext_catch_incomplete_ref;
+ IncompleteCatchIsInvalid = false;
}
if (!Invalid && (Mode == 0 || !BaseType->isVoidType()) &&
- !BaseType->isDependentType() && RequireCompleteType(Loc, BaseType, DK))
+ !BaseType->isDependentType() && RequireCompleteType(Loc, BaseType, DK) &&
+ IncompleteCatchIsInvalid)
Invalid = true;
if (!Invalid && !ExDeclType->isDependentType() &&
Modified: cfe/trunk/test/SemaCXX/exceptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/exceptions.cpp?rev=97927&r1=97926&r2=97927&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/exceptions.cpp (original)
+++ cfe/trunk/test/SemaCXX/exceptions.cpp Sun Mar 7 19:47:36 2010
@@ -12,8 +12,8 @@
} catch(float i) {
} catch(void v) { // expected-error {{cannot catch incomplete type 'void'}}
} catch(A a) { // expected-error {{cannot catch incomplete type 'struct A'}}
- } catch(A *a) { // expected-error {{cannot catch pointer to incomplete type 'struct A'}}
- } catch(A &a) { // expected-error {{cannot catch reference to incomplete type 'struct A'}}
+ } catch(A *a) { // expected-warning {{pointer to incomplete type 'struct A'}}
+ } catch(A &a) { // expected-warning {{reference to incomplete type 'struct A'}}
} catch(Abstract) { // expected-error {{variable type 'Abstract' is an abstract class}}
} catch(...) {
int j = i; // expected-error {{use of undeclared identifier 'i'}}
Modified: cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp?rev=97927&r1=97926&r2=97927&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp Sun Mar 7 19:47:36 2010
@@ -194,7 +194,7 @@
template<typename T> struct TryCatch0 {
void f() {
try {
- } catch (T t) { // expected-error{{incomplete type}} \
+ } catch (T t) { // expected-warning{{incomplete type}} \
// expected-error{{abstract class}}
} catch (...) {
}
More information about the cfe-commits
mailing list