[PATCH] D155573: [Clang] Fix the location of default init expressions
Corentin Jabot via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 18 05:32:20 PDT 2023
cor3ntin updated this revision to Diff 541473.
cor3ntin added a comment.
Address Aaron's comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155573/new/
https://reviews.llvm.org/D155573
Files:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp
clang/test/SemaCXX/source_location.cpp
Index: clang/test/SemaCXX/source_location.cpp
===================================================================
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -1,5 +1,6 @@
// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s
+// RUN: %clang_cc1 -std=c++2b -fcxx-exceptions -DUSE_CONSTEVAL -DPAREN_INIT -fexceptions -verify %s
// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fms-extensions -DMS -fexceptions -verify %s
// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fms-extensions -DMS -DUSE_CONSTEVAL -fexceptions -verify %s
// expected-no-diagnostics
@@ -781,3 +782,18 @@
static_assert(f<int>() != // intentional new line
f<int>());
}
+
+#ifdef PAREN_INIT
+namespace GH63903 {
+struct S {
+ int _;
+ int i = SL::current().line();
+ int j = __builtin_LINE();
+};
+// Ensure parent aggregate initialization is consistent with brace
+// aggregate initialization.
+static_assert(S(0).i == S{0}.i);
+static_assert(S(0).j == S{0}.j);
+static_assert(S(0).j == S{0}.i);
+}
+#endif
Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===================================================================
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -294,3 +294,14 @@
}
}
+
+namespace GH63903 {
+ constexpr int f(); // expected-note {{declared here}}
+ struct S {
+ int a = 0, b = f(); // expected-note {{undefined function 'f' cannot be used in a constant expression}}
+ };
+
+ // Test that errors produced by default members are produced at the location of the initialization
+ constexpr S s(0); // beforecxx20-warning {{aggregate initialization of type 'const S' from a parenthesized list of values is a C++20 extension}} \
+ // expected-error {{constexpr variable 's' must be initialized by a constant expression}}
+}
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5593,7 +5593,8 @@
// C++ [dcl.init]p16.6.2.2
// The remaining elements are initialized with their default
// member initializers, if any
- ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), FD);
+ ExprResult DIE = S.BuildCXXDefaultInitExpr(
+ Kind.getParenOrBraceRange().getEnd(), FD);
if (DIE.isInvalid())
return;
S.checkInitializerLifetime(SubEntity, DIE.get());
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -707,6 +707,9 @@
- Fix crash when emitting diagnostic for out of order designated initializers
in C++.
(`#63605 <https://github.com/llvm/llvm-project/issues/63605>`_)
+- Fix location of default member initialization in parenthesized aggregate
+ initialization.
+ (`#63903 <https://github.com/llvm/llvm-project/issues/63903>`_)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155573.541473.patch
Type: text/x-patch
Size: 3203 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230718/966d7f0f/attachment-0001.bin>
More information about the cfe-commits
mailing list