[PATCH] Correctly set brace range for CXXConstructExprs formed by list initialization.
Peter Collingbourne
peter at pcc.me.uk
Wed Feb 5 16:45:43 PST 2014
Hi rsmith,
http://llvm-reviews.chandlerc.com/D2711
Files:
lib/Sema/SemaInit.cpp
test/Analysis/inlining/path-notes.cpp
unittests/AST/SourceLocationTest.cpp
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -5232,10 +5232,13 @@
ConstructKind = CXXConstructExpr::CK_Delegating;
}
- // Only get the parenthesis range if it is a direct construction.
- SourceRange parenRange =
- Kind.getKind() == InitializationKind::IK_Direct ?
- Kind.getParenRange() : SourceRange();
+ // Only get the parenthesis or brace range if it is a list initialization or
+ // direct construction.
+ SourceRange ParenOrBraceRange;
+ if (IsListInitialization)
+ ParenOrBraceRange = SourceRange(LBraceLoc, RBraceLoc);
+ else if (Kind.getKind() == InitializationKind::IK_Direct)
+ ParenOrBraceRange = Kind.getParenRange();
// If the entity allows NRVO, mark the construction as elidable
// unconditionally.
@@ -5247,16 +5250,16 @@
IsListInitialization,
ConstructorInitRequiresZeroInit,
ConstructKind,
- parenRange);
+ ParenOrBraceRange);
else
CurInit = S.BuildCXXConstructExpr(Loc, Entity.getType(),
Constructor,
ConstructorArgs,
HadMultipleCandidates,
IsListInitialization,
ConstructorInitRequiresZeroInit,
ConstructKind,
- parenRange);
+ ParenOrBraceRange);
}
if (CurInit.isInvalid())
return ExprError();
Index: test/Analysis/inlining/path-notes.cpp
===================================================================
--- test/Analysis/inlining/path-notes.cpp
+++ test/Analysis/inlining/path-notes.cpp
@@ -1506,7 +1506,7 @@
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>line</key><integer>120</integer>
-// CHECK-NEXT: <key>col</key><integer>19</integer>
+// CHECK-NEXT: <key>col</key><integer>20</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
@@ -1535,7 +1535,7 @@
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>line</key><integer>120</integer>
-// CHECK-NEXT: <key>col</key><integer>19</integer>
+// CHECK-NEXT: <key>col</key><integer>20</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
@@ -1787,7 +1787,7 @@
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>line</key><integer>128</integer>
-// CHECK-NEXT: <key>col</key><integer>32</integer>
+// CHECK-NEXT: <key>col</key><integer>33</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
Index: unittests/AST/SourceLocationTest.cpp
===================================================================
--- unittests/AST/SourceLocationTest.cpp
+++ unittests/AST/SourceLocationTest.cpp
@@ -211,6 +211,16 @@
functionalCastExpr(), Lang_CXX11));
}
+TEST(CXXConstructExpr, SourceRange) {
+ RangeVerifier<CXXConstructExpr> Verifier;
+ Verifier.expectRange(3, 14, 3, 19);
+ EXPECT_TRUE(Verifier.match(
+ "struct A { A(int, int); };\n"
+ "void f(A a);\n"
+ "void g() { f({0, 0}); }",
+ constructExpr(), Lang_CXX11));
+}
+
TEST(CXXTemporaryObjectExpr, SourceRange) {
RangeVerifier<CXXTemporaryObjectExpr> Verifier;
Verifier.expectRange(2, 6, 2, 12);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2711.1.patch
Type: text/x-patch
Size: 3913 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140205/f5dbad35/attachment.bin>
More information about the cfe-commits
mailing list