[PATCH] D59874: [PR41247] Fixed parsing of private keyword in C++

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 04:47:50 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL357162: [PR41247] Fixed parsing of private keyword in C++. (authored by stulova, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59874?vs=192485&id=192611#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59874/new/

https://reviews.llvm.org/D59874

Files:
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/lib/Parse/ParseTentative.cpp
  cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp


Index: cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp
===================================================================
--- cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp
+++ cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp
@@ -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}}
Index: cfe/trunk/lib/Parse/ParseDecl.cpp
===================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp
+++ cfe/trunk/lib/Parse/ParseDecl.cpp
@@ -4791,7 +4791,6 @@
 
   case tok::kw___kindof:
 
-  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
@@ -4800,9 +4799,11 @@
   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 @@
 
   case tok::kw___kindof:
 
-  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
@@ -4995,6 +4995,9 @@
 #include "clang/Basic/OpenCLImageTypes.def"
 
     return true;
+
+  case tok::kw_private:
+    return getLangOpts().OpenCL;
   }
 }
 
@@ -5196,6 +5199,9 @@
 
     // 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: cfe/trunk/lib/Parse/ParseTentative.cpp
===================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp
+++ cfe/trunk/lib/Parse/ParseTentative.cpp
@@ -1414,8 +1414,13 @@
     // 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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59874.192611.patch
Type: text/x-patch
Size: 2435 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190328/31512afe/attachment-0001.bin>


More information about the llvm-commits mailing list