c++/2645: Boost-related const & typdef in template puzzle
pcarlini@unitus.it
pcarlini@unitus.it
Wed Apr 25 13:36:00 GMT 2001
>Number: 2645
>Category: c++
>Synopsis: Boost-related const & typdef in template puzzle
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Apr 25 13:36:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Paolo Carlini
>Release: 3.0 20010423 (prerelease) & Codesourcery
>Organization:
>Environment:
i686, Linux2.2.19, glibc2.2.2, binutils2.11
>Description:
This puzzle surfaced while analyzing Boost's testsuite
failure of call_traits_test.cpp.
That code assumes that two typedefs (for a const int&) are
equivalent to an explicit const int & in order to specify
a template type, but this is not the case for Gcc2.95.2
and Gcc3.0.
The following code, which does compile (and should not!),
illustrates the case:
template <typename T>
struct call_traits
{
public:
typedef T type_less_spec;
};
template <typename T>
struct call_traits<T&>
{
typedef T type_more_spec;
};
int main()
{
int num;
// Two typedefs lead to the instant. of the less spec. ("wrong") template
typedef int& r_type;
typedef const r_type cr_type;
call_traits<cr_type>::type_less_spec var1 = num;
// ^^^^^^^^^^^^^^
// The explicit type leads to the instantiation of the "correct" one
call_traits<const int&>::type_more_spec var2 = num;
// ^^^^^^^^^^^^^^
// As happen with a single typedef!
typedef const int& std_cr_type;
call_traits<std_cr_type>::type_more_spec var3 = num;
// As happen, indeed, without the cv-qualifier
call_traits<r_type>::type_more_spec var4;
}
>How-To-Repeat:
Before submitting the bug report, I cross checked with
two other (commonly believed) very ISO-compliant compilers,
which, indeed, rejected the testcase.
>Fix:
????
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list