public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-modules] Block-scope externs disallowed
@ 2020-10-09 15:21 Nathan Sidwell
0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-10-09 15:21 UTC (permalink / raw)
To: gcc-cvs
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" }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-10-09 15:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-09 15:21 [gcc/devel/c++-modules] Block-scope externs disallowed Nathan Sidwell
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).