PR c++/55663 - constexpr function templ instantiation
authordodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 15 Jan 2013 09:12:30 +0000 (09:12 +0000)
committerdodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 15 Jan 2013 09:12:30 +0000 (09:12 +0000)
commit14144bb9f07bb9f1c5834d3eb70e4f0c2bb5b4b7
treeb55d0860e61bfea46c17cab939daafaff581504a
parent8365f6c8309554c056301464f9d94ea161c688a4
PR c++/55663 - constexpr function templ instantiation

Consider the example of the problem report

     1 template <typename>
     2 constexpr bool the_truth () { return true; }
     3
     4 template <bool>
     5   struct Takes_bool { };
     6
     7 template<bool B>
     8   using Alias = Takes_bool<B>;
     9
    10 template<typename T>
    11   struct test { using type = Alias<the_truth<T>()>; };
    12
    13 int main () {
    14   test<int> a;
    15
    16   return 0;
    17 }

that yields the error:

    test.cc: In substitution of ‘template<bool B> using Alias = Takes_bool<B> [with bool B = the_truth<int>()]’:
    test.cc:11:51:   required from ‘struct test<int>’
    test.cc:14:13:   required from here
    test.cc:11:51: error: integral expression ‘the_truth<int>()’ is not constant
       struct test { using type = Alias<the_truth<T>()>; };

I think the issue happens in the course of instantiating test<int> at
line 14, when we look into instantiating Alias<the_truth<T>()> (at
line 11) (using instantiate_alias_template) with T = int.

There, when we check the argument 'the_truth<int>()' to see if it
actually is a constant expression, in check_instantiated_arg, we fail
to recognize it constexpr-ness b/c we just look at its TREE_CONSTANT.

At that point, the_truth<int> should have been folded, and it's not,
because instantiate_alias_template forgets to call
coerce_template_parms on its arguments.

Fixed thus, bootstapped and tested on x86_64-unknown-linux-gnu against
trunk.

gcc/cp/

PR c++/55663
* pt.c (coerce_innermost_template_parms): New static function.
(instantiate_alias_template):  Use it here.

gcc/testsuite/

PR c++/55663
* g++.dg/cpp0x/alias-decl-31.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@195189 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/alias-decl-31.C [new file with mode: 0644]