diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2014-07-08 18:18:04 +0000 |
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2014-07-08 18:18:04 +0000 |
| commit | 03f705fe92dc51c1b2a7746d9b25c59040aede43 (patch) | |
| tree | 9e879bc0ef2ed57b50a550dae7ad00bcabd8735f /clang/lib/Sema/SemaDeclCXX.cpp | |
| parent | 42b107a4eccb52069c0cfe83154f7da59ae3d0af (diff) | |
| download | bcm5719-llvm-03f705fe92dc51c1b2a7746d9b25c59040aede43.tar.gz bcm5719-llvm-03f705fe92dc51c1b2a7746d9b25c59040aede43.zip | |
Sema: Don't allow CVR qualifiers before structors
We would silently accept volatile ~S() when the user probably intended
to write virtual ~S().
This fixes PR20238.
llvm-svn: 212555
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 621ba1daa18..99eedf34872 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -6279,6 +6279,15 @@ QualType Sema::CheckConstructorDeclarator(Declarator &D, QualType R, SC = SC_None; } + if (unsigned TypeQuals = D.getDeclSpec().getTypeQualifiers()) { + diagnoseIgnoredQualifiers( + diag::err_constructor_return_type, TypeQuals, SourceLocation(), + D.getDeclSpec().getConstSpecLoc(), D.getDeclSpec().getVolatileSpecLoc(), + D.getDeclSpec().getRestrictSpecLoc(), + D.getDeclSpec().getAtomicSpecLoc()); + D.setInvalidType(); + } + DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo(); if (FTI.TypeQuals != 0) { if (FTI.TypeQuals & Qualifiers::Const) @@ -6426,7 +6435,7 @@ QualType Sema::CheckDestructorDeclarator(Declarator &D, QualType R, SC = SC_None; } - if (D.getDeclSpec().hasTypeSpecifier() && !D.isInvalidType()) { + if (!D.isInvalidType()) { // Destructors don't have return types, but the parser will // happily parse something like: // @@ -6435,9 +6444,19 @@ QualType Sema::CheckDestructorDeclarator(Declarator &D, QualType R, // }; // // The return type will be eliminated later. - Diag(D.getIdentifierLoc(), diag::err_destructor_return_type) - << SourceRange(D.getDeclSpec().getTypeSpecTypeLoc()) - << SourceRange(D.getIdentifierLoc()); + if (D.getDeclSpec().hasTypeSpecifier()) + Diag(D.getIdentifierLoc(), diag::err_destructor_return_type) + << SourceRange(D.getDeclSpec().getTypeSpecTypeLoc()) + << SourceRange(D.getIdentifierLoc()); + else if (unsigned TypeQuals = D.getDeclSpec().getTypeQualifiers()) { + diagnoseIgnoredQualifiers(diag::err_destructor_return_type, TypeQuals, + SourceLocation(), + D.getDeclSpec().getConstSpecLoc(), + D.getDeclSpec().getVolatileSpecLoc(), + D.getDeclSpec().getRestrictSpecLoc(), + D.getDeclSpec().getAtomicSpecLoc()); + D.setInvalidType(); + } } DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo(); |

