Bug 39475 - c++0x type-traits should error out in case of incompleteness
Summary: c++0x type-traits should error out in case of incompleteness
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.2
: P3 normal
Target Milestone: 4.4.0
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-16 19:04 UTC by Daniel Frey
Modified: 2009-03-17 20:50 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-03-16 19:20:13


Attachments
show inconsistency for is_abstract (345 bytes, text/plain)
2009-03-16 19:05 UTC, Daniel Frey
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Frey 2009-03-16 19:04:15 UTC
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.
Comment 1 Daniel Frey 2009-03-16 19:05:37 UTC
Created attachment 17468 [details]
show inconsistency for is_abstract
Comment 2 Paolo Carlini 2009-03-16 19:20:13 UTC
Indeed, ICC errors out.
Comment 3 Daniel Frey 2009-03-16 23:49:12 UTC
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/...?
Comment 4 Paolo Carlini 2009-03-17 00:34:49 UTC
Maybe Daniel, but this is a completely separate issue.
Comment 5 Daniel Frey 2009-03-17 07:30:37 UTC
(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
Comment 6 paolo@gcc.gnu.org 2009-03-17 20:49:39 UTC
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

Comment 7 Paolo Carlini 2009-03-17 20:50:26 UTC
Fixed for 4.4.0.