summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-12-21 02:55:12 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-12-21 02:55:12 +0000
commit242ad89a15d5466d166d47978bfff983d40ab511 (patch)
tree6dbdd5a89a0874ea2545ebb1c6d6089fbc5dfa49 /clang/test
parentb9ccd553fca066e8f5e1353e612ef91bb85d20d1 (diff)
downloadbcm5719-llvm-242ad89a15d5466d166d47978bfff983d40ab511.tar.gz
bcm5719-llvm-242ad89a15d5466d166d47978bfff983d40ab511.zip
C++11 half of r147023: In C++11, additionally eagerly instantiate:
- constexpr function template instantiations - variables of reference type - constexpr variables llvm-svn: 147031
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp5
-rw-r--r--clang/test/SemaCXX/constant-expression-cxx11.cpp46
2 files changed, 19 insertions, 32 deletions
diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp
index 0fb6f7def00..809a0cb1763 100644
--- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp
@@ -68,7 +68,7 @@ struct ConstexprDtor {
};
// template stuff
-template <typename T> constexpr T ft(T t) { return t; } // unexpected-note {{here}}
+template <typename T> constexpr T ft(T t) { return t; }
template <typename T> T gt(T t) { return t; }
struct S {
template<typename T> constexpr T f();
@@ -89,8 +89,7 @@ template <> int S::g() const; // desired-error {{non-constexpr declaration of 'g
template <> char S::g() { return 0; } // expected-error {{no function template matches}}
template <> double S::g() const { return 0; } // ok
-// FIXME: The initializer is a constant expression.
-constexpr int i3 = ft(1); // unexpected-error {{must be initialized by a constant expression}} unexpected-note {{undefined function 'ft<int>'}}
+constexpr int i3 = ft(1);
void test() {
// ignore constexpr when instantiating with non-literal
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 5798eb59485..b470c80619d 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -8,16 +8,17 @@ static_assert(false, "test"); // expected-error {{test}}
}
-template<typename T> constexpr T id(const T &t) { return t; } // expected-note {{here}}
-// FIXME: support templates here.
-//template<typename T> constexpr T min(const T &a, const T &b) {
-// return a < b ? a : b;
-//}
-//template<typename T> constexpr T max(const T &a, const T &b) {
-// return a < b ? b : a;
-//}
-constexpr int min(const int &a, const int &b) { return a < b ? a : b; }
-constexpr int max(const int &a, const int &b) { return a < b ? b : a; }
+typedef decltype(sizeof(char)) size_t;
+
+template<typename T> constexpr T id(const T &t) { return t; }
+template<typename T> constexpr T min(const T &a, const T &b) {
+ return a < b ? a : b;
+}
+template<typename T> constexpr T max(const T &a, const T &b) {
+ return a < b ? b : a;
+}
+template<typename T, size_t N> constexpr T *begin(T (&xs)[N]) { return xs; }
+template<typename T, size_t N> constexpr T *end(T (&xs)[N]) { return xs + N; }
struct MemberZero {
constexpr int zero() { return 0; }
@@ -84,8 +85,7 @@ namespace TemplateArgumentConversion {
template<int n> struct IntParam {};
using IntParam0 = IntParam<0>;
- // FIXME: This should be accepted once we implement the new ICE rules.
- using IntParam0 = IntParam<id(0)>; // expected-error {{not an integral constant expression}}
+ using IntParam0 = IntParam<id(0)>;
using IntParam0 = IntParam<MemberZero().zero>; // expected-error {{did you mean to call it with no arguments?}} expected-error {{not an integral constant expression}}
}
@@ -94,8 +94,7 @@ namespace CaseStatements {
switch (n) {
// FIXME: Produce the 'add ()' fixit for this.
case MemberZero().zero: // desired-error {{did you mean to call it with no arguments?}} expected-error {{not an integer constant expression}} expected-note {{non-literal type '<bound member function type>'}}
- // FIXME: This should be accepted once we implement the new ICE rules.
- case id(1): // expected-error {{not an integer constant expression}} expected-note {{undefined function}}
+ case id(1):
return;
}
}
@@ -352,14 +351,8 @@ constexpr int strcmp_ce(const char *p, const char *q) {
namespace StringLiteral {
-// FIXME: Refactor this once we support constexpr templates.
-constexpr int MangleChars(const char *p) {
- return *p + 3 * (*p ? MangleChars(p+1) : 0);
-}
-constexpr int MangleChars(const char16_t *p) {
- return *p + 3 * (*p ? MangleChars(p+1) : 0);
-}
-constexpr int MangleChars(const char32_t *p) {
+template<typename Char>
+constexpr int MangleChars(const Char *p) {
return *p + 3 * (*p ? MangleChars(p+1) : 0);
}
@@ -383,9 +376,6 @@ constexpr const char *max_element(const char *a, const char *b) {
return (a+1 >= b) ? a : max_iter(a, max_element(a+1, b));
}
-constexpr const char *begin(const char (&arr)[45]) { return arr; }
-constexpr const char *end(const char (&arr)[45]) { return arr + 45; }
-
constexpr char str[] = "the quick brown fox jumped over the lazy dog";
constexpr const char *max = max_element(begin(str), end(str));
static_assert(*max == 'z', "");
@@ -400,12 +390,10 @@ static_assert(strcmp_ce("", " ") < 0, "");
namespace Array {
-// FIXME: Use templates for these once we support constexpr templates.
-constexpr int Sum(const int *begin, const int *end) {
+template<typename Iter>
+constexpr auto Sum(Iter begin, Iter end) -> decltype(+*begin) {
return begin == end ? 0 : *begin + Sum(begin+1, end);
}
-constexpr const int *begin(const int (&xs)[5]) { return xs; }
-constexpr const int *end(const int (&xs)[5]) { return xs + 5; }
constexpr int xs[] = { 1, 2, 3, 4, 5 };
constexpr int ys[] = { 5, 4, 3, 2, 1 };
OpenPOWER on IntegriCloud