]> granicus.if.org Git - clang/commitdiff
[PR41247] Fixed parsing of private keyword in C++.
authorAnastasia Stulova <anastasia.stulova@arm.com>
Thu, 28 Mar 2019 11:47:14 +0000 (11:47 +0000)
committerAnastasia Stulova <anastasia.stulova@arm.com>
Thu, 28 Mar 2019 11:47:14 +0000 (11:47 +0000)
Fixed bug in C++ to prevent parsing 'private' as a
valid address space qualifier.

Differential Revision: https://reviews.llvm.org/D59874

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357162 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseDecl.cpp
lib/Parse/ParseTentative.cpp
test/SemaOpenCLCXX/private-access-specifier.cpp [new file with mode: 0644]

index 688347bd2dfadc90f756d9a9e87ab147df56cfa5..130cd9f20652b18ebe83e2a13bd768bfcb5ca0a2 100644 (file)
@@ -4791,7 +4791,6 @@ bool Parser::isTypeSpecifierQualifier() {
 
   case tok::kw___kindof:
 
-  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
@@ -4800,9 +4799,11 @@ bool Parser::isTypeSpecifierQualifier() {
   case tok::kw___read_only:
   case tok::kw___read_write:
   case tok::kw___write_only:
-
     return true;
 
+  case tok::kw_private:
+    return getLangOpts().OpenCL;
+
   // C11 _Atomic
   case tok::kw__Atomic:
     return true;
@@ -4982,7 +4983,6 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
 
   case tok::kw___kindof:
 
-  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
@@ -4995,6 +4995,9 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
 #include "clang/Basic/OpenCLImageTypes.def"
 
     return true;
+
+  case tok::kw_private:
+    return getLangOpts().OpenCL;
   }
 }
 
@@ -5196,6 +5199,9 @@ void Parser::ParseTypeQualifierListOpt(
 
     // OpenCL qualifiers:
     case tok::kw_private:
+      if (!getLangOpts().OpenCL)
+        goto DoneWithTypeQuals;
+      LLVM_FALLTHROUGH;
     case tok::kw___private:
     case tok::kw___global:
     case tok::kw___local:
index d0549a9725d860bc896c3f97fd719e9d18e973c4..46366ff43cfacb7daede0b0d9bbad3c3e46cc043 100644 (file)
@@ -1414,8 +1414,13 @@ Parser::isCXXDeclarationSpecifier(Parser::TPResult BracedCastResult,
     // cv-qualifier
   case tok::kw_const:
   case tok::kw_volatile:
+    return TPResult::True;
+
     // OpenCL address space qualifiers
   case tok::kw_private:
+    if (!getLangOpts().OpenCL)
+      return TPResult::False;
+    LLVM_FALLTHROUGH;
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
diff --git a/test/SemaOpenCLCXX/private-access-specifier.cpp b/test/SemaOpenCLCXX/private-access-specifier.cpp
new file mode 100644 (file)
index 0000000..2aff228
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -pedantic -verify -fsyntax-only
+
+// Test that 'private' is not parsed as an address space qualifier
+// in regular C++ mode.
+
+struct B {
+  virtual ~B() // expected-error{{expected ';' at end of declaration list}}
+private:
+   void foo();
+   private int* i; // expected-error{{expected ':'}}
+};
+
+void bar(private int*); //expected-error{{variable has incomplete type 'void'}} expected-error{{expected expression}}