]> granicus.if.org Git - clang/commitdiff
Fix a bug in VarDecl::getSourceRange() for static member arrays with an element
authorNico Weber <nicolasweber@gmx.de>
Tue, 22 Jan 2013 17:00:09 +0000 (17:00 +0000)
committerNico Weber <nicolasweber@gmx.de>
Tue, 22 Jan 2013 17:00:09 +0000 (17:00 +0000)
type with an implicit initializer expression.

Patch from Will Wilson <will@indefiant.com>!

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

lib/AST/Decl.cpp
test/SemaCXX/sourceranges.cpp

index c053b6d17e3d49eb253fc67e50b660f9c6bae165..7a5181432511dc5aca40faa11f8533b4f7df4d98 100644 (file)
@@ -1206,7 +1206,9 @@ void VarDecl::setStorageClass(StorageClass SC) {
 SourceRange VarDecl::getSourceRange() const {
   if (const Expr *Init = getInit()) {
     SourceLocation InitEnd = Init->getLocEnd();
-    if (InitEnd.isValid())
+    // If Init is implicit, ignore its source range and fallback on 
+    // DeclaratorDecl::getSourceRange() to handle postfix elements.
+    if (InitEnd.isValid() && InitEnd != getLocation())
       return SourceRange(getOuterLocStart(), InitEnd);
   }
   return DeclaratorDecl::getSourceRange();
index 0537aa20d5e92425c2758c48f3675b2930d96099..1f25d5bce93cae385a7531b2c1dee249930e867e 100644 (file)
@@ -7,11 +7,14 @@ class P {
 };
 
 namespace foo {
-class A {};
+class A { public: A() {} };
 enum B {};
 typedef int C;
 }
 
+// CHECK: VarDecl {{0x[0-9a-fA-F]+}} <line:16:1, col:36> ImplicitConstrArray 'foo::A [2]'
+static foo::A ImplicitConstrArray[2];
+
 int main() {
   // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::A *'
   P<foo::A> p14 = new foo::A;