public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-modules] Concepts and local externs
@ 2020-09-14 12:54 Nathan Sidwell
0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-09-14 12:54 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:a1fed5312efcfedb047f51714a29370675b9af86
commit a1fed5312efcfedb047f51714a29370675b9af86
Author: Nathan Sidwell <nathan@acm.org>
Date: Fri Sep 11 11:42:07 2020 -0700
Concepts and local externs
gcc/cp/
* decl.c (grokfndecl): Don't attach to local extern.
gcc/testsuite/
* concepts/local-extern.C: New.
Diff:
---
ChangeLog.modules | 6 +++++
gcc/cp/decl.c | 13 +++++++---
gcc/cp/module.cc | 5 ++++
gcc/testsuite/g++.dg/concepts/local-extern.C | 39 ++++++++++++++++++++++++++++
4 files changed, 59 insertions(+), 4 deletions(-)
diff --git a/ChangeLog.modules b/ChangeLog.modules
index 9801ec197a9..85798763a5f 100644
--- a/ChangeLog.modules
+++ b/ChangeLog.modules
@@ -1,5 +1,11 @@
2020-09-11 Nathan Sidwell <nathan@acm.org>
+ Concepts and local externs
+ gcc/cp/
+ * decl.c (grokfndecl): Don't attach to local extern.
+ gcc/testsuite/
+ * concepts/local-extern.C: New.
+
Local extern fns do not get template header
gcc/cp/
* module.cc (trees_out::chained_decls): Also mark local fns for
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 10dce3a13e2..4a8ebc121e8 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9503,7 +9503,10 @@ grokfndecl (tree ctype,
{
tree tmpl_reqs = NULL_TREE;
tree ctx = friendp ? current_class_type : ctype;
- bool memtmpl = (processing_template_decl > template_class_depth (ctx));
+ bool block_local = TREE_CODE (current_scope ()) == FUNCTION_DECL;
+ bool memtmpl = (!block_local
+ && (processing_template_decl
+ > template_class_depth (ctx)));
if (memtmpl)
tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
tree ci = build_constraints (tmpl_reqs, decl_reqs);
@@ -9513,9 +9516,11 @@ grokfndecl (tree ctype,
ci = NULL_TREE;
}
/* C++20 CA378: Remove non-templated constrained functions. */
- if (ci && !flag_concepts_ts
- && (!processing_template_decl
- || (friendp && !memtmpl && !funcdef_flag)))
+ if (ci
+ && (block_local
+ || (!flag_concepts_ts
+ && (!processing_template_decl
+ || (friendp && !memtmpl && !funcdef_flag)))))
{
error_at (location, "constraints on a non-templated function");
ci = NULL_TREE;
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index af13b45b0c7..cc529220026 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -9869,6 +9869,11 @@ trees_out::get_merge_kind (tree decl, depset *dep)
out-of-class definition. For instance a FIELD_DECL. */
tree ctx = CP_DECL_CONTEXT (decl);
if (TREE_CODE (ctx) == FUNCTION_DECL)
+ // FIXME: This not right if DECL has a template header. For
+ // those will have instantiations pointing at it. I think the
+ // only case is class definitions inside templates (including
+ // lambdas). At least those have an ABI-mandated
+ // disambiguation mechanism that we can leverage.
return MK_unique;
if (TREE_CODE (decl) == TEMPLATE_DECL
diff --git a/gcc/testsuite/g++.dg/concepts/local-extern.C b/gcc/testsuite/g++.dg/concepts/local-extern.C
new file mode 100644
index 00000000000..69ecc2361c0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/local-extern.C
@@ -0,0 +1,39 @@
+// { dg-do compile { target c++17 } }
+// { dg-additional-options -fconcepts }
+
+// Don't attach constraints to block-scope fn-decls and ICE
+
+template<typename _Iter>
+ concept input_or_output_iterator
+ = requires(_Iter __i) { { *__i } ; };
+
+
+ template<input_or_output_iterator _It>
+ class common_iterator
+ {
+
+ public:
+
+void
+ frob ()
+ {
+ if (__builtin_is_constant_evaluated())
+ {
+ void __failed_assertion(); // ICEd
+ if (!bool(_M_index == 0)) __failed_assertion();
+ }
+
+ }
+
+ private:
+ unsigned char _M_index;
+ };
+
+template <typename T> concept C = true;
+
+template<typename T>
+void F ()
+{
+ void bad () requires C<T>; // { dg-error "a non-templated function" }
+
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-09-14 12:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-14 12:54 [gcc/devel/c++-modules] Concepts and local externs 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).