This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2cbf5127d585: [Clang] Improve designated inits diagnostic 
location (authored by void).

Changed prior to commit:
  https://reviews.llvm.org/D147673?vs=511529&id=511749#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147673/new/

https://reviews.llvm.org/D147673

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/cxx2b-designated-initializers.cpp


Index: clang/test/SemaCXX/cxx2b-designated-initializers.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/cxx2b-designated-initializers.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify %s
+
+namespace PR61118 {
+
+union S {
+  struct {
+    int a;
+  };
+};
+
+void f(int x, auto) {
+  const S result { // expected-error {{field designator (null) does not refer 
to any field in type 'const S'}}
+    .a = x
+  };
+}
+
+void g(void) {
+  f(0, 0); // expected-note {{in instantiation of function template 
specialization 'PR61118::f<int>' requested here}}
+}
+
+} // end namespace PR61118
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2641,8 +2641,15 @@
           hadError = true;
         } else {
           // Typo correction didn't find anything.
-          SemaRef.Diag(D->getFieldLoc(), diag::err_field_designator_unknown)
-            << FieldName << CurrentObjectType;
+          SourceLocation Loc = D->getFieldLoc();
+
+          // The loc can be invalid with a "null" designator (i.e. an anonymous
+          // union/struct). Do our best to approximate the location.
+          if (Loc.isInvalid())
+            Loc = IList->getBeginLoc();
+
+          SemaRef.Diag(Loc, diag::err_field_designator_unknown)
+            << FieldName << CurrentObjectType << DIE->getSourceRange();
           ++Index;
           return true;
         }


Index: clang/test/SemaCXX/cxx2b-designated-initializers.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/cxx2b-designated-initializers.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify %s
+
+namespace PR61118 {
+
+union S {
+  struct {
+    int a;
+  };
+};
+
+void f(int x, auto) {
+  const S result { // expected-error {{field designator (null) does not refer to any field in type 'const S'}}
+    .a = x
+  };
+}
+
+void g(void) {
+  f(0, 0); // expected-note {{in instantiation of function template specialization 'PR61118::f<int>' requested here}}
+}
+
+} // end namespace PR61118
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2641,8 +2641,15 @@
           hadError = true;
         } else {
           // Typo correction didn't find anything.
-          SemaRef.Diag(D->getFieldLoc(), diag::err_field_designator_unknown)
-            << FieldName << CurrentObjectType;
+          SourceLocation Loc = D->getFieldLoc();
+
+          // The loc can be invalid with a "null" designator (i.e. an anonymous
+          // union/struct). Do our best to approximate the location.
+          if (Loc.isInvalid())
+            Loc = IList->getBeginLoc();
+
+          SemaRef.Diag(Loc, diag::err_field_designator_unknown)
+            << FieldName << CurrentObjectType << DIE->getSourceRange();
           ++Index;
           return true;
         }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to