Hi!

With the using-directive parsing changes, we now emit only a warning
for [[omp::directive (...)]] on using-directive.  While that is right
without -fopenmp/-fopenmp-simd, when OpenMP is enabled, that should
be an error as OpenMP (is going to) disallow such attributes there
as they do not appertain to a statement.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2021-08-12  Jakub Jelinek  <ja...@redhat.com>

        * name-lookup.c (finish_using_directive): Diagnose omp::directive
        or omp::sequence attributes on using-directive.

        * g++.dg/gomp/attrs-11.C: Adjust expected diagnostics.

--- gcc/cp/name-lookup.c.jj     2021-06-10 19:56:20.606335462 +0200
+++ gcc/cp/name-lookup.c        2021-08-11 22:33:51.367221663 +0200
@@ -8560,6 +8560,7 @@ finish_using_directive (tree target, tree attribs)
   add_using_namespace (current_binding_level->using_directives,
                       ORIGINAL_NAMESPACE (target));
 
+  bool diagnosed = false;
   if (attribs != error_mark_node)
     for (tree a = attribs; a; a = TREE_CHAIN (a))
       {
@@ -8572,6 +8573,16 @@ finish_using_directive (tree target, tree attribs)
              inform (DECL_SOURCE_LOCATION (target),
                      "you can use an inline namespace instead");
          }
+       else if ((flag_openmp || flag_openmp_simd)
+                && get_attribute_namespace (a) == omp_identifier
+                && (is_attribute_p ("directive", name)
+                    || is_attribute_p ("sequence", name)))
+         {
+           if (!diagnosed)
+             error ("%<omp::%E%> not allowed to be specified in this "
+                    "context", name);
+           diagnosed = true;
+         }
        else
          warning (OPT_Wattributes, "%qD attribute directive ignored", name);
       }
--- gcc/testsuite/g++.dg/gomp/attrs-11.C.jj     2021-08-11 16:56:49.262489927 
+0200
+++ gcc/testsuite/g++.dg/gomp/attrs-11.C        2021-08-11 22:34:59.427281071 
+0200
@@ -11,7 +11,7 @@ foo ()
   [[omp::directive (parallel)]] __extension__ asm ("");                // { 
dg-error "expected" }
   __extension__ [[omp::directive (parallel)]] asm ("");                // { 
dg-error "expected" }
   [[omp::directive (parallel)]] namespace M = ::N;             // { dg-error 
"expected" }
-  [[omp::directive (parallel)]] using namespace N;             // { dg-bogus 
"expected" "" { xfail *-*-* } }
+  [[omp::directive (parallel)]] using namespace N;             // { dg-error 
"not allowed to be specified in this context" }
   [[omp::directive (parallel)]] using O::T;                    // { dg-error 
"expected" }
   [[omp::directive (parallel)]] __label__ foo;                 // { dg-error 
"expected" }
   [[omp::directive (parallel)]] static_assert (true, "");      // { dg-error 
"expected" }


        Jakub

Reply via email to