public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH 2/2] c++: make trait of incomplete type a permerror [PR109277]
Date: Thu, 13 Apr 2023 14:59:21 -0400	[thread overview]
Message-ID: <20230413185921.2201433-2-jason@redhat.com> (raw)
In-Reply-To: <20230413185921.2201433-1-jason@redhat.com>

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


      reply	other threads:[~2023-04-13 18:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

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=20230413185921.2201433-2-jason@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@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).