diff mbox

[C++] Fix __is_base_of vs incomplete types

Message ID 52A3B01A.6070006@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Dec. 7, 2013, 11:32 p.m. UTC
Hi,

noticed this while preparing some testcases for the library (but 
probably Daniel pointed it out together with related issues some time 
ago): if we don't handle separately identical types modulo 
cv-qualifiers, we incorrectly return false for incomplete types.

Tested x86_64-linux.

Thanks,
Paolo.

////////////////////////
/cp
2013-12-07  Paolo Carlini  <paolo.carlini@oracle.com>

	* semantics.c (trait_expr_value, [CPTK_IS_BASE_OF]): Implement
	the letter of 20.11.6 about Base and Derived naming the same
	class type modulo cv-qualifiers.

/testsuite
2013-12-07  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/ext/is_base_of_incomplete-2.C: New.

Comments

Jason Merrill Dec. 12, 2013, 4:01 a.m. UTC | #1
Hmm, what if we make lookup_base handle incomplete types better?

Jason
Paolo Carlini Dec. 12, 2013, 4:27 a.m. UTC | #2
Hi,

On 12/12/2013 05:01 AM, Jason Merrill wrote:
> Hmm, what if we make lookup_base handle incomplete types better?
I'm leaving for a few days of vacations, then I can certainly look into 
that, per se should be very doable. To be honest, I didn't consider that 
possibility because I feared it could be risky wrt all the other users 
of lookup_base, which are many. Do you think it would be safe for 4.9?

Thanks,
Paolo.
Jason Merrill Dec. 12, 2013, 2:19 p.m. UTC | #3
I wouldn't expect it to cause problems.

Jason
diff mbox

Patch

Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 205782)
+++ cp/semantics.c	(working copy)
@@ -7108,7 +7108,8 @@  trait_expr_value (cp_trait_kind kind, tree type1,
 
     case CPTK_IS_BASE_OF:
       return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
-	      && DERIVED_FROM_P (type1, type2));
+	      && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
+		  || DERIVED_FROM_P (type1, type2)));
 
     case CPTK_IS_CLASS:
       return (NON_UNION_CLASS_TYPE_P (type1));
Index: testsuite/g++.dg/ext/is_base_of_incomplete-2.C
===================================================================
--- testsuite/g++.dg/ext/is_base_of_incomplete-2.C	(revision 0)
+++ testsuite/g++.dg/ext/is_base_of_incomplete-2.C	(working copy)
@@ -0,0 +1,5 @@ 
+struct T;
+
+int check1[__is_base_of(T, T) ? 1 : -1];
+int check2[__is_base_of(T, const T) ? 1 : -1];
+int check3[__is_base_of(volatile T, T) ? 1 : -1];