diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-12-23 21:06:06 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-12-23 21:06:06 +0000 |
commit | 721fb2b6e4059d5054428ac13fee36dfab9962ef (patch) | |
tree | f7973d0684e4470ea4891a0e6bdde5356175e11d /clang/lib/Sema | |
parent | b8e6dc88bb6467cb09a7707d22996d7b24d01123 (diff) | |
download | bcm5719-llvm-721fb2b6e4059d5054428ac13fee36dfab9962ef.tar.gz bcm5719-llvm-721fb2b6e4059d5054428ac13fee36dfab9962ef.zip |
Diagnose the use of incomplete types in C++ typeid expressions
llvm-svn: 92045
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index d395673e75b..afb5c54d65c 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -37,7 +37,22 @@ Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc, // that is the operand of typeid are always ignored. // FIXME: Preserve type source info. // FIXME: Preserve the type before we stripped the cv-qualifiers? - TyOrExpr =GetTypeFromParser(TyOrExpr).getUnqualifiedType().getAsOpaquePtr(); + QualType T = GetTypeFromParser(TyOrExpr); + if (T.isNull()) + return ExprError(); + + // C++ [expr.typeid]p4: + // If the type of the type-id is a class type or a reference to a class + // type, the class shall be completely-defined. + QualType CheckT = T; + if (const ReferenceType *RefType = CheckT->getAs<ReferenceType>()) + CheckT = RefType->getPointeeType(); + + if (CheckT->getAs<RecordType>() && + RequireCompleteType(OpLoc, CheckT, diag::err_incomplete_typeid)) + return ExprError(); + + TyOrExpr = T.getUnqualifiedType().getAsOpaquePtr(); } IdentifierInfo *TypeInfoII = &PP.getIdentifierTable().get("type_info"); @@ -66,7 +81,8 @@ Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc, // C++ [expr.typeid]p3: // [...] If the type of the expression is a class type, the class // shall be completely-defined. - // FIXME: implement this! + if (RequireCompleteType(OpLoc, T, diag::err_incomplete_typeid)) + return ExprError(); } } |