]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: implicit lookup of std::initializer_list [PR102576]
authorPatrick Palka <ppalka@redhat.com>
Thu, 29 Sep 2022 20:27:30 +0000 (16:27 -0400)
committerPatrick Palka <ppalka@redhat.com>
Thu, 29 Sep 2022 20:27:30 +0000 (16:27 -0400)
Here the lookup for the implicit use of std::initializer_list fails
because we do it using get_namespace_binding, which isn't import aware.
Fix this by using lookup_qualified_name instead.

PR c++/102576

gcc/cp/ChangeLog:

* pt.cc (listify): Use lookup_qualified_name instead of
get_namespace_binding.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr102576_a.H: New test.
* g++.dg/modules/pr102576_b.C: New test.

gcc/cp/pt.cc
gcc/testsuite/g++.dg/modules/pr102576_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr102576_b.C [new file with mode: 0644]

index 0f92374f19ade1c0ea3e76d9653a1a257452ec67..258f76d6e476f8b0420a3e54ceec93bcf324deca 100644 (file)
@@ -29161,9 +29161,10 @@ finish_concept_definition (cp_expr id, tree init)
 static tree
 listify (tree arg)
 {
-  tree std_init_list = get_namespace_binding (std_node, init_list_identifier);
+  tree std_init_list = lookup_qualified_name (std_node, init_list_identifier);
 
-  if (!std_init_list || !DECL_CLASS_TEMPLATE_P (std_init_list))
+  if (std_init_list == error_mark_node
+      || !DECL_CLASS_TEMPLATE_P (std_init_list))
     {
       gcc_rich_location richloc (input_location);
       maybe_add_include_fixit (&richloc, "<initializer_list>", false);
diff --git a/gcc/testsuite/g++.dg/modules/pr102576_a.H b/gcc/testsuite/g++.dg/modules/pr102576_a.H
new file mode 100644 (file)
index 0000000..87ba9b5
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/102576
+// { dg-additional-options -fmodule-header }
+// { dg-module-cmi {} }
+
+#include <initializer_list>
diff --git a/gcc/testsuite/g++.dg/modules/pr102576_b.C b/gcc/testsuite/g++.dg/modules/pr102576_b.C
new file mode 100644 (file)
index 0000000..10251ed
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/102576
+// { dg-additional-options -fmodules-ts }
+
+import "pr102576_a.H";
+
+int main() {
+  for (int i : {1, 2, 3})
+    ;
+}