Fix a bug in VarDecl::getSourceRange() for static member arrays with an element

type with an implicit initializer expression.

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

llvm-svn: 173170
This commit is contained in:
Nico Weber 2013-01-22 17:00:09 +00:00
parent 6029d4f3ae
commit bbe1394c96
2 changed files with 7 additions and 2 deletions

View 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();

View 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;