diff options
author | Marco Antognini <marco.antognini@arm.com> | 2019-07-22 09:39:13 +0000 |
---|---|---|
committer | Marco Antognini <marco.antognini@arm.com> | 2019-07-22 09:39:13 +0000 |
commit | 88559637641e993895337e1047a0bd787fecc647 (patch) | |
tree | 639b057daba633db68b8fa4d34a957913786c64f /clang/lib/Sema/SemaDeclCXX.cpp | |
parent | 6771a89fa01ffb1ea8702d7b07e259750ae62f1c (diff) | |
download | bcm5719-llvm-88559637641e993895337e1047a0bd787fecc647.tar.gz bcm5719-llvm-88559637641e993895337e1047a0bd787fecc647.zip |
[OpenCL] Improve destructor support in C++ for OpenCL
This re-applies r366422 with a fix for Bug PR42665 and a new regression
test.
llvm-svn: 366670
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index dd77fc55721..9a6385f2831 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -8190,6 +8190,27 @@ void Sema::ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *MethodD) { CheckCXXDefaultArguments(Method); } +// Emit the given diagnostic for each non-address-space qualifier. +// Common part of CheckConstructorDeclarator and CheckDestructorDeclarator. +static void checkMethodTypeQualifiers(Sema &S, Declarator &D, unsigned DiagID) { + const DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo(); + if (FTI.hasMethodTypeQualifiers() && !D.isInvalidType()) { + bool DiagOccured = false; + FTI.MethodQualifiers->forEachQualifier( + [DiagID, &S, &DiagOccured](DeclSpec::TQ, StringRef QualName, + SourceLocation SL) { + // This diagnostic should be emitted on any qualifier except an addr + // space qualifier. However, forEachQualifier currently doesn't visit + // addr space qualifiers, so there's no way to write this condition + // right now; we just diagnose on everything. + S.Diag(SL, DiagID) << QualName << SourceRange(SL); + DiagOccured = true; + }); + if (DiagOccured) + D.setInvalidType(); + } +} + /// CheckConstructorDeclarator - Called by ActOnDeclarator to check /// the well-formedness of the constructor declarator @p D with type @p /// R. If there are any errors in the declarator, this routine will @@ -8230,25 +8251,11 @@ QualType Sema::CheckConstructorDeclarator(Declarator &D, QualType R, D.setInvalidType(); } - DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo(); - if (FTI.hasMethodTypeQualifiers()) { - bool DiagOccured = false; - FTI.MethodQualifiers->forEachQualifier( - [&](DeclSpec::TQ TypeQual, StringRef QualName, SourceLocation SL) { - // This diagnostic should be emitted on any qualifier except an addr - // space qualifier. However, forEachQualifier currently doesn't visit - // addr space qualifiers, so there's no way to write this condition - // right now; we just diagnose on everything. - Diag(SL, diag::err_invalid_qualified_constructor) - << QualName << SourceRange(SL); - DiagOccured = true; - }); - if (DiagOccured) - D.setInvalidType(); - } + checkMethodTypeQualifiers(*this, D, diag::err_invalid_qualified_constructor); // C++0x [class.ctor]p4: // A constructor shall not be declared with a ref-qualifier. + DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo(); if (FTI.hasRefQualifier()) { Diag(FTI.getRefQualifierLoc(), diag::err_ref_qualifier_constructor) << FTI.RefQualifierIsLValueRef @@ -8423,18 +8430,11 @@ QualType Sema::CheckDestructorDeclarator(Declarator &D, QualType R, } } - DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo(); - if (FTI.hasMethodTypeQualifiers() && !D.isInvalidType()) { - FTI.MethodQualifiers->forEachQualifier( - [&](DeclSpec::TQ TypeQual, StringRef QualName, SourceLocation SL) { - Diag(SL, diag::err_invalid_qualified_destructor) - << QualName << SourceRange(SL); - }); - D.setInvalidType(); - } + checkMethodTypeQualifiers(*this, D, diag::err_invalid_qualified_destructor); // C++0x [class.dtor]p2: // A destructor shall not be declared with a ref-qualifier. + DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo(); if (FTI.hasRefQualifier()) { Diag(FTI.getRefQualifierLoc(), diag::err_ref_qualifier_destructor) << FTI.RefQualifierIsLValueRef |