aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2019-08-23 19:29:16 -0400
committerJason Merrill <jason@gcc.gnu.org>2019-08-23 19:29:16 -0400
commit5b93b053495e46aaf29811f1ac23d7f484be6ea9 (patch)
tree73f2917ced232884dd4de094b544aa95290e992c /gcc
parent01c53a74cd594131d9b066eb3036c6245562dc41 (diff)
downloadgcc-5b93b053495e46aaf29811f1ac23d7f484be6ea9.zip
gcc-5b93b053495e46aaf29811f1ac23d7f484be6ea9.tar.gz
gcc-5b93b053495e46aaf29811f1ac23d7f484be6ea9.tar.bz2
Fix handling of namespace-scope undeduced auto decls.
* decl2.c (decl_dependent_p): New. (mark_used): Check it instead of just processing_template_decl. From-SVN: r274894
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/decl2.c24
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/constexpr-if30.C10
3 files changed, 38 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0643755..86d1849 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,10 @@
2019-08-22 Jason Merrill <jason@redhat.com>
+ * decl2.c (decl_dependent_p): New.
+ (mark_used): Check it instead of just processing_template_decl.
+
+2019-08-22 Jason Merrill <jason@redhat.com>
+
* parser.c (cp_parser_nested_name_specifier_opt): Avoid redundant
error.
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index aca37a2..36c6f4c 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -5425,6 +5425,25 @@ cp_warn_deprecated_use_scopes (tree scope)
}
}
+/* True if DECL or its enclosing scope have unbound template parameters. */
+
+bool
+decl_dependent_p (tree decl)
+{
+ if (DECL_FUNCTION_SCOPE_P (decl)
+ || TREE_CODE (decl) == CONST_DECL
+ || TREE_CODE (decl) == USING_DECL
+ || TREE_CODE (decl) == FIELD_DECL)
+ decl = CP_DECL_CONTEXT (decl);
+ if (tree tinfo = get_template_info (decl))
+ if (any_dependent_template_arguments_p (TI_ARGS (tinfo)))
+ return true;
+ if (LAMBDA_FUNCTION_P (decl)
+ && dependent_type_p (DECL_CONTEXT (decl)))
+ return true;
+ return false;
+}
+
/* Mark DECL (either a _DECL or a BASELINK) as "used" in the program.
If DECL is a specialization or implicitly declared class member,
generate the actual definition. Return false if something goes
@@ -5451,6 +5470,9 @@ mark_used (tree decl, tsubst_flags_t complain)
decl = OVL_FIRST (decl);
}
+ if (!DECL_P (decl))
+ return true;
+
/* Set TREE_USED for the benefit of -Wunused. */
TREE_USED (decl) = 1;
/* And for structured bindings also the underlying decl. */
@@ -5498,7 +5520,7 @@ mark_used (tree decl, tsubst_flags_t complain)
|| DECL_LANG_SPECIFIC (decl) == NULL
|| DECL_THUNK_P (decl))
{
- if (!processing_template_decl
+ if (!decl_dependent_p (decl)
&& !require_deduced_type (decl, complain))
return false;
return true;
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if30.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if30.C
new file mode 100644
index 0000000..1e3d15d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if30.C
@@ -0,0 +1,10 @@
+// { dg-do compile { target c++17 } }
+
+auto fn = [](auto i) {
+ if constexpr (sizeof(i) == 1)
+ return fn(123); // { dg-error "auto" }
+};
+
+int main() {
+ fn('!');
+}