Bug 43646 - [C++0x] decltype and std::integral_constant
Summary: [C++0x] decltype and std::integral_constant
Status: RESOLVED DUPLICATE of bug 48617
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-05 11:38 UTC by Jonathan Wakely
Modified: 2011-06-18 19:15 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.4.3, 4.5.0
Last reconfirmed: 2010-04-05 12:56:39


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2010-04-05 11:38:15 UTC
This was originally sent as an email to gcc-bugs:
http://gcc.gnu.org/ml/gcc-bugs/2010-04/msg00167.html
I'm entering it here on his behalf...

The following translation unit seems to show a bug exhibited by 4.4.3 and 4.5. 

    #include <type_traits> 

    template<class X, class Y> struct plus 
        : std::integral_constant< 
            decltype(X::value + Y::value), 
            X::value + Y::value 
        > { }; 

    int main(int argc, char* argv[]) { 
        return 0; 
    } 

Compiling this file (test.cpp) with 

    g++ -std=c++0x -l stdc++ test.cpp 

yields the following diagnostic: 

    test.cpp:7: error: 'decltype ((X::value + Y::value))' 
    is not a valid type for a template constant parameter 

Am I missing something? The following works as intended: 

    #include <type_traits> 
    #include <utility> 

    template<class X, class Y> struct plus 
        : std::integral_constant< 
            typename std::identity<decltype(X::value + Y::value)>::type, 
            X::value + Y::value 
        > { }; 

    int main(int argc, char* argv[]) { 
        return 0; 
    } 

(i.e. just wrapping the use of decltype with std::identity)
Comment 1 Jonathan Wakely 2010-04-05 11:39:55 UTC
Is this related to DR 743 or 950, and so likely to get fixed when N3049 is supported?
Comment 2 Wolfgang Bangerth 2010-04-05 12:56:39 UTC
I think this should work. I can't see how it would be invalid as template
argument for integral_constant but valid for identity.

W.
Comment 3 Jason Merrill 2011-06-18 19:15:09 UTC
Fixed already.

*** This bug has been marked as a duplicate of bug 48617 ***