[PATCH] Do not add enums to prototype scope in C++ modes.

Peter Collingbourne peter at pcc.me.uk
Tue Feb 11 09:42:55 PST 2014


Hi rsmith,

The language forbids defining enums in prototypes, so this check is normally
redundant, but if an enum is defined during template instantiation it should
not be added to the prototype scope.

http://llvm-reviews.chandlerc.com/D2742

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaTemplate/instantiate-enum.cpp

Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -12952,7 +12952,7 @@
 
   // If we're declaring a function, ensure this decl isn't forgotten about -
   // it needs to go into the function scope.
-  if (InFunctionDeclarator)
+  if (!getLangOpts().CPlusPlus && InFunctionDeclarator)
     DeclsInPrototypeScope.push_back(Enum);
 
   CheckForDuplicateEnumValues(*this, Elements, Enum, EnumType);
Index: test/SemaTemplate/instantiate-enum.cpp
===================================================================
--- test/SemaTemplate/instantiate-enum.cpp
+++ test/SemaTemplate/instantiate-enum.cpp
@@ -25,3 +25,18 @@
 
   template void f<int>();
 }
+
+namespace EnumScoping {
+
+template <typename T>
+class C {
+  enum {
+    value = 42
+  };
+};
+
+void f(int i, C<int>::C c) {
+  int value;
+}
+
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2742.1.patch
Type: text/x-patch
Size: 900 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140211/50d16d6b/attachment.bin>


More information about the cfe-commits mailing list