* [PATCH 1/2] c++: make cxx_incomplete_type_diagnostic return bool
@ 2023-04-13 18:59 Jason Merrill
2023-04-13 18:59 ` [PATCH 2/2] c++: make trait of incomplete type a permerror [PR109277] Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2023-04-13 18:59 UTC (permalink / raw)
To: gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
Like other diagnostic functions that might be silenced by options, it should
return whether or not it actually emitted a diagnostic.
gcc/cp/ChangeLog:
* typeck2.cc (cxx_incomplete_type_diagnostic): Return bool.
* cp-tree.h (cxx_incomplete_type_diagnostic): Adjust.
---
gcc/cp/cp-tree.h | 8 ++++----
gcc/cp/typeck2.cc | 34 ++++++++++++++++++----------------
2 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 622752ae4e6..a14eb8d0b9a 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -8155,7 +8155,7 @@ extern void maybe_warn_pessimizing_move (tree, tree, bool);
/* in typeck2.cc */
extern void require_complete_eh_spec_types (tree, tree);
-extern void cxx_incomplete_type_diagnostic (location_t, const_tree,
+extern bool cxx_incomplete_type_diagnostic (location_t, const_tree,
const_tree, diagnostic_t);
inline location_t
loc_or_input_loc (location_t loc)
@@ -8178,12 +8178,12 @@ cp_expr_loc_or_input_loc (const_tree t)
return cp_expr_loc_or_loc (t, input_location);
}
-inline void
+inline bool
cxx_incomplete_type_diagnostic (const_tree value, const_tree type,
diagnostic_t diag_kind)
{
- cxx_incomplete_type_diagnostic (cp_expr_loc_or_input_loc (value),
- value, type, diag_kind);
+ return cxx_incomplete_type_diagnostic (cp_expr_loc_or_input_loc (value),
+ value, type, diag_kind);
}
extern void cxx_incomplete_type_error (location_t, const_tree,
diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc
index c56b69164e2..76a7a7f6b98 100644
--- a/gcc/cp/typeck2.cc
+++ b/gcc/cp/typeck2.cc
@@ -292,7 +292,7 @@ cxx_incomplete_type_inform (const_tree type)
and TYPE is the type that was invalid. DIAG_KIND indicates the
type of diagnostic (see diagnostic.def). */
-void
+bool
cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
const_tree type, diagnostic_t diag_kind)
{
@@ -304,7 +304,7 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
/* Avoid duplicate error message. */
if (TREE_CODE (type) == ERROR_MARK)
- return;
+ return false;
if (value)
{
@@ -336,7 +336,7 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
break;
case VOID_TYPE:
- emit_diagnostic (diag_kind, loc, 0,
+ complained = emit_diagnostic (diag_kind, loc, 0,
"invalid use of %qT", type);
break;
@@ -346,7 +346,7 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
type = TREE_TYPE (type);
goto retry;
}
- emit_diagnostic (diag_kind, loc, 0,
+ complained = emit_diagnostic (diag_kind, loc, 0,
"invalid use of array with unspecified bounds");
break;
@@ -365,12 +365,12 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
add a fix-it hint. */
if (type_num_arguments (TREE_TYPE (member)) == 1)
richloc.add_fixit_insert_after ("()");
- emit_diagnostic (diag_kind, &richloc, 0,
+ complained = emit_diagnostic (diag_kind, &richloc, 0,
"invalid use of member function %qD "
"(did you forget the %<()%> ?)", member);
}
else
- emit_diagnostic (diag_kind, loc, 0,
+ complained = emit_diagnostic (diag_kind, loc, 0,
"invalid use of member %qD "
"(did you forget the %<&%> ?)", member);
}
@@ -380,38 +380,38 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
if (is_auto (type))
{
if (CLASS_PLACEHOLDER_TEMPLATE (type))
- emit_diagnostic (diag_kind, loc, 0,
+ complained = emit_diagnostic (diag_kind, loc, 0,
"invalid use of placeholder %qT", type);
else
- emit_diagnostic (diag_kind, loc, 0,
+ complained = emit_diagnostic (diag_kind, loc, 0,
"invalid use of %qT", type);
}
else
- emit_diagnostic (diag_kind, loc, 0,
+ complained = emit_diagnostic (diag_kind, loc, 0,
"invalid use of template type parameter %qT", type);
break;
case BOUND_TEMPLATE_TEMPLATE_PARM:
- emit_diagnostic (diag_kind, loc, 0,
+ complained = emit_diagnostic (diag_kind, loc, 0,
"invalid use of template template parameter %qT",
TYPE_NAME (type));
break;
case TYPE_PACK_EXPANSION:
- emit_diagnostic (diag_kind, loc, 0,
+ complained = emit_diagnostic (diag_kind, loc, 0,
"invalid use of pack expansion %qT", type);
break;
case TYPENAME_TYPE:
case DECLTYPE_TYPE:
- emit_diagnostic (diag_kind, loc, 0,
+ complained = emit_diagnostic (diag_kind, loc, 0,
"invalid use of dependent type %qT", type);
break;
case LANG_TYPE:
if (type == init_list_type_node)
{
- emit_diagnostic (diag_kind, loc, 0,
+ complained = emit_diagnostic (diag_kind, loc, 0,
"invalid use of brace-enclosed initializer list");
break;
}
@@ -419,20 +419,22 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
if (value && TREE_CODE (value) == COMPONENT_REF)
goto bad_member;
else if (value && TREE_CODE (value) == ADDR_EXPR)
- emit_diagnostic (diag_kind, loc, 0,
+ complained = emit_diagnostic (diag_kind, loc, 0,
"address of overloaded function with no contextual "
"type information");
else if (value && TREE_CODE (value) == OVERLOAD)
- emit_diagnostic (diag_kind, loc, 0,
+ complained = emit_diagnostic (diag_kind, loc, 0,
"overloaded function with no contextual type information");
else
- emit_diagnostic (diag_kind, loc, 0,
+ complained = emit_diagnostic (diag_kind, loc, 0,
"insufficient contextual information to determine type");
break;
default:
gcc_unreachable ();
}
+
+ return complained;
}
/* Print an error message for invalid use of an incomplete type.
base-commit: 66c7257b675068fe62505d74873371fd0508b499
--
2.31.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] c++: make trait of incomplete type a permerror [PR109277]
2023-04-13 18:59 [PATCH 1/2] c++: make cxx_incomplete_type_diagnostic return bool Jason Merrill
@ 2023-04-13 18:59 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-04-13 18:59 UTC (permalink / raw)
To: gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
An incomplete type argument to several traits is specified to be undefined
behavior in the library; since it's a compile-time property, we diagnose
it. But apparently some code was relying on the previous behavior of not
diagnosing. So let's make it a permerror.
The assert in cxx_incomplete_type_diagnostic didn't like that, and I don't
see the point of having the assert, so let's just remove it.
PR c++/109277
gcc/cp/ChangeLog:
* semantics.cc (check_trait_type): Handle incomplete type directly.
* typeck2.cc (cxx_incomplete_type_diagnostic): Remove assert.
gcc/testsuite/ChangeLog:
* g++.dg/ext/is_convertible5.C: New test.
---
gcc/cp/semantics.cc | 7 ++++++-
gcc/cp/typeck2.cc | 4 ----
gcc/testsuite/g++.dg/ext/is_convertible5.C | 7 +++++++
3 files changed, 13 insertions(+), 5 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/ext/is_convertible5.C
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 99a76e3ed65..45e0b0e81d3 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12107,7 +12107,12 @@ check_trait_type (tree type, int kind = 1)
if (VOID_TYPE_P (type))
return true;
- return !!complete_type_or_else (strip_array_types (type), NULL_TREE);
+ type = complete_type (strip_array_types (type));
+ if (!COMPLETE_TYPE_P (type)
+ && cxx_incomplete_type_diagnostic (NULL_TREE, type, DK_PERMERROR)
+ && !flag_permissive)
+ return false;
+ return true;
}
/* Process a trait expression. */
diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc
index 76a7a7f6b98..bf03967a71f 100644
--- a/gcc/cp/typeck2.cc
+++ b/gcc/cp/typeck2.cc
@@ -298,10 +298,6 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
{
bool is_decl = false, complained = false;
- gcc_assert (diag_kind == DK_WARNING
- || diag_kind == DK_PEDWARN
- || diag_kind == DK_ERROR);
-
/* Avoid duplicate error message. */
if (TREE_CODE (type) == ERROR_MARK)
return false;
diff --git a/gcc/testsuite/g++.dg/ext/is_convertible5.C b/gcc/testsuite/g++.dg/ext/is_convertible5.C
new file mode 100644
index 00000000000..ab9be05afea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_convertible5.C
@@ -0,0 +1,7 @@
+// PR c++/109277
+// { dg-do compile { target c++11 } }
+// { dg-options -fpermissive }
+
+struct a;
+struct b{};
+static_assert (!__is_convertible (a, b), ""); // { dg-warning "incomplete" }
--
2.31.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-04-13 18:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-13 18:59 [PATCH 1/2] c++: make cxx_incomplete_type_diagnostic return bool Jason Merrill
2023-04-13 18:59 ` [PATCH 2/2] c++: make trait of incomplete type a permerror [PR109277] Jason Merrill
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).