Commit 3ea33585 by Martin Sebor Committed by Martin Sebor

PR c++/53792 - [C++11] improving compiler-time constexpr evaluation

gcc/testsuite/ChangeLog:
2016-03-14  Martin Sebor  <msebor@redhat.com>

	PR c++/53792
	* g++.dg/cpp0x/constexpr-inline.C: New test.
	* g++.dg/cpp0x/constexpr-inline-1.C: Same.

From-SVN: r234208
parent 08a1cadc
2016-03-14 Martin Sebor <msebor@redhat.com>
PR c++/53792
* g++.dg/cpp0x/constexpr-inline.C: New test.
* g++.dg/cpp0x/constexpr-inline-1.C: Same.
2016-03-14 David Edelsohn <dje.gcc@gmail.com> 2016-03-14 David Edelsohn <dje.gcc@gmail.com>
* gcc.dg/torture/pr70083.c: Prune non-standard ABI. * gcc.dg/torture/pr70083.c: Prune non-standard ABI.
......
// PR c++/53792 - [C++11] improving compiler-time constexpr evaluation
// Test case from comment #8.
// { dg-do compile { target c++14 } }
// { dg-additional-options "-O1 -fdump-tree-optimized" }
template <class T>
void sink (T);
constexpr unsigned foo ()
{
unsigned i = 1;
while ((i << 1) > i)
i = i << 1;
return i;
}
template <unsigned N>
struct S { };
void bar ()
{
sink (foo ());
sink (S<foo ()>());
}
// Verify that the call to the foo() constexpr function is inlined
// regardless of whether or not it's invoked in a constant expression.
// { dg-final { scan-tree-dump-not "= *foo *\\\(" "optimized" } }
// PR c++/53792 - [C++11] improving compiler-time constexpr evaluation
// { dg-do compile { target c++11 } }
// { dg-additional-options "-O1 -fdump-tree-optimized" }
struct entry
{
char const* label;
int value;
};
constexpr bool same (char const *x, char const *y)
{
return !*x && !*y ? true : /* default */ (*x == *y && same (x + 1, y + 1));
}
constexpr int
keyToValue (char const *label, entry const *entries)
{
return !entries->label ? entries->value
: same (entries->label, label) ? entries->value
: /* default */ keyToValue (label, entries + 1);
}
constexpr entry foo[] = {{"Foo", 0}, {"Bar", 1}, {"FooBar", 2}, {0, -1}};
int bar ()
{
int result = keyToValue ("Foo", foo);
return result;
}
int baz ()
{
constexpr int result = keyToValue ("Foo", foo);
return result;
}
// Verify that the call to the keyToValue() constexpr function is inlined
// regardless of whether or not it's invoked in a constexpr expression.
// { dg-final { scan-tree-dump-not "keyToValue" "optimized" } }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment