[cfe-commits] r96729 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclBase.h lib/AST/Decl.cpp lib/Sema/SemaDecl.cpp test/CXX/class/class.nest/p3.cpp
Chandler Carruth
chandlerc at gmail.com
Sat Feb 20 23:08:09 PST 2010
Author: chandlerc
Date: Sun Feb 21 01:08:09 2010
New Revision: 96729
URL: http://llvm.org/viewvc/llvm-project?rev=96729&view=rev
Log:
Make Decl::isOutOfLine() virtual, and use that to determine when definitions
are for out of line declarations more easily. This simplifies the logic and
handles the case of out-of-line class definitions correctly. Fixes PR6107.
Added:
cfe/trunk/test/CXX/class/class.nest/p3.cpp
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=96729&r1=96728&r2=96729&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sun Feb 21 01:08:09 2010
@@ -561,7 +561,7 @@
/// \brief Determine whether this is or was instantiated from an out-of-line
/// definition of a static data member.
- bool isOutOfLine() const;
+ virtual bool isOutOfLine() const;
/// \brief If this is a static data member, find its out-of-line definition.
VarDecl *getOutOfLineDefinition();
@@ -1306,7 +1306,7 @@
/// \brief Determine whether this is or was instantiated from an out-of-line
/// definition of a member function.
- bool isOutOfLine() const;
+ virtual bool isOutOfLine() const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=96729&r1=96728&r2=96729&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Sun Feb 21 01:08:09 2010
@@ -331,7 +331,7 @@
return const_cast<Decl*>(this)->getLexicalDeclContext();
}
- bool isOutOfLine() const {
+ virtual bool isOutOfLine() const {
return getLexicalDeclContext() != getDeclContext();
}
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=96729&r1=96728&r2=96729&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Sun Feb 21 01:08:09 2010
@@ -680,12 +680,12 @@
}
bool VarDecl::isOutOfLine() const {
- if (!isStaticDataMember())
- return false;
-
if (Decl::isOutOfLine())
return true;
-
+
+ if (!isStaticDataMember())
+ return false;
+
// If this static data member was instantiated from a static data member of
// a class template, check whether that static data member was defined
// out-of-line.
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=96729&r1=96728&r2=96729&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Feb 21 01:08:09 2010
@@ -436,14 +436,15 @@
if (AddToContext)
CurContext->addDecl(D);
- // Out-of-line function and variable definitions should not be pushed into
- // scope.
- if ((isa<FunctionTemplateDecl>(D) &&
- cast<FunctionTemplateDecl>(D)->getTemplatedDecl()->isOutOfLine()) ||
- (isa<FunctionDecl>(D) &&
- (cast<FunctionDecl>(D)->isFunctionTemplateSpecialization() ||
- cast<FunctionDecl>(D)->isOutOfLine())) ||
- (isa<VarDecl>(D) && cast<VarDecl>(D)->isOutOfLine()))
+ // Out-of-line definitions shouldn't be pushed into scope in C++.
+ // Out-of-line variable and function definitions shouldn't even in C.
+ if ((getLangOptions().CPlusPlus || isa<VarDecl>(D) || isa<FunctionDecl>(D)) &&
+ D->isOutOfLine())
+ return;
+
+ // Template instantiations should also not be pushed into scope.
+ if (isa<FunctionDecl>(D) &&
+ cast<FunctionDecl>(D)->isFunctionTemplateSpecialization())
return;
// If this replaces anything in the current scope,
Added: cfe/trunk/test/CXX/class/class.nest/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.nest/p3.cpp?rev=96729&view=auto
==============================================================================
--- cfe/trunk/test/CXX/class/class.nest/p3.cpp (added)
+++ cfe/trunk/test/CXX/class/class.nest/p3.cpp Sun Feb 21 01:08:09 2010
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// C++0x [class.nest] p3:
+// If class X is defined in a namespace scope, a nested class Y may be
+// declared in class X and later defined in the definition of class X or be
+// later defined in a namespace scope enclosing the definition of class X.
+
+namespace example {
+ class E {
+ class I1;
+ class I2;
+ class I1 { };
+ };
+ class E::I2 { };
+}
+
+// Don't insert out-of-line inner class definitions into the namespace scope.
+namespace PR6107 {
+ struct S1 { };
+ struct S2 {
+ struct S1;
+ };
+ struct S2::S1 { };
+ S1 s1;
+}
More information about the cfe-commits
mailing list