public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/c++-modules] Block-scope externs disallowed
Date: Fri,  9 Oct 2020 15:21:47 +0000 (GMT)	[thread overview]
Message-ID: <20201009152147.104CE3857C55@sourceware.org> (raw)

https://gcc.gnu.org/g:3152c118ca04efb2605cc796b1be58d75a6465b2

commit 3152c118ca04efb2605cc796b1be58d75a6465b2
Author: Nathan Sidwell <nathan@acm.org>
Date:   Fri Oct 9 08:21:30 2020 -0700

    Block-scope externs disallowed
    
            gcc/cp/
            * decl.c (start_decl): Reject block-scope extern in module
            purview.
            gcc/testsuite/
            * g++.dg/modules/local-extern-1.C: New.

Diff:
---
 ChangeLog.modules                             |  7 +++++++
 gcc/cp/decl.c                                 | 11 ++++++++---
 gcc/testsuite/g++.dg/modules/local-extern-1.C | 20 ++++++++++++++++++++
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/ChangeLog.modules b/ChangeLog.modules
index 61dcf53141b..40a31624223 100644
--- a/ChangeLog.modules
+++ b/ChangeLog.modules
@@ -1,5 +1,12 @@
 2020-10-09  Nathan Sidwell  <nathan@acm.org>
 
+	Block-scope externs disallowed
+	gcc/cp/
+	* decl.c (start_decl): Reject block-scope extern in module
+	purview.
+	gcc/testsuite/
+	* g++.dg/modules/local-extern-1.C: New.
+
 	Remove unused code
 	gcc/cp/
 	* friend.c (add_friend): Remove #if'd out code
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 169204e26bb..baa32d71123 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5445,9 +5445,14 @@ start_decl (const cp_declarator *declarator,
 
   if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
       && current_function_decl)
-    /* A function-scope decl of some namespace-scope decl.  */
-    // FIXME: This is ill-formed in a named module
-    DECL_LOCAL_DECL_P (decl) = true;
+    {
+      /* A function-scope decl of some namespace-scope decl.  */
+      DECL_LOCAL_DECL_P (decl) = true;
+      if (named_module_purview_p ())
+	error_at (declarator->id_loc,
+		  "block-scope extern declaration %q#D not permitted"
+		  " in module purview", decl);
+    }
 
   /* Enter this declaration into the symbol table.  Don't push the plain
      VAR_DECL for a variable template.  */
diff --git a/gcc/testsuite/g++.dg/modules/local-extern-1.C b/gcc/testsuite/g++.dg/modules/local-extern-1.C
new file mode 100644
index 00000000000..7b016053d36
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/local-extern-1.C
@@ -0,0 +1,20 @@
+// { dg-additional-options "-fmodules-ts -Wno-pedantic" }
+
+module;
+# 4 __FILE__ 1
+inline void frob ()
+{
+  extern int bob; // OK
+}
+
+# 11 "" 2
+export module bob;
+// { dg-module-cmi !bob }
+
+inline void dob ()
+{
+  extern int bob; // { dg-error "block-scope extern" }
+}
+
+
+// { dg-prune-output "not writing module" }


                 reply	other threads:[~2020-10-09 15:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201009152147.104CE3857C55@sourceware.org \
    --to=nathan@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).