The current implementation returns misleading results if used the wrong way. A simple example is: #include <iostream> struct X; int main() { std::cout << __is_abstract(X) << std::endl; } compiles and prints "0". Things get worse when templates are involved. PR libstdc++/39405 shows why this can be a real problem. I attach the example code from 39405 to this PR again.
Created attachment 17468 [details] show inconsistency for is_abstract
Indeed, ICC errors out.
One more thought on the diagnostics: There are two cases: Incomplete types (like in the initial example in the description of this PR) and recursive template instantiations (see attachment). I think the latter produces a diagnostic which suggests it is the former. This problem not only affects C++0x, it also happens for "normal" C++: frey@viasko:~/work/test/recursive_instantiation$ cat t.cc template< typename T > struct foo { typename T::type dummy(); }; template< typename T > struct bar { typedef void type; foo< bar > p; }; foo< bar< int > > x; frey@viasko:~/work/test/recursive_instantiation$ g++ t.cc t.cc: In instantiation of 'bar<int>': t.cc:4: instantiated from 'foo<bar<int> >' t.cc:14: instantiated from here t.cc:11: error: 'bar<T>::p' has incomplete type t.cc:3: error: declaration of 'struct foo<bar<int> >' frey@viasko:~/work/test/recursive_instantiation$ g++ is Ubuntu's GCC 4.3.2. The error message says bar<T>::p is incomplete, but there is no hint why this is the case. Would it be possible to generally improve this type of diagnostic? Should I open yet another PR or is that not possible/worth it/...?
Maybe Daniel, but this is a completely separate issue.
(In reply to comment #4) > Maybe Daniel, but this is a completely separate issue. That's why I asked if I should open yet another PR for it :) I've done that now: PR c++/39478
Subject: Bug 39475 Author: paolo Date: Tue Mar 17 20:49:23 2009 New Revision: 144919 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144919 Log: /cp 2009-03-17 Paolo Carlini <paolo.carlini@oracle.com> PR c++/39475 * semantics.c (check_trait_type): New. (finish_trait_expr): Use it. /testsuite 2009-03-17 Paolo Carlini <paolo.carlini@oracle.com> PR c++/39475 * g++.dg/ext/unary_trait_incomplete.C: New. Added: trunk/gcc/testsuite/g++.dg/ext/unary_trait_incomplete.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/semantics.c trunk/gcc/testsuite/ChangeLog
Fixed for 4.4.0.