diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-03-11 23:10:44 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-03-11 23:10:44 +0000 |
commit | 6f4596cfb70ec706dd2da38db1be3663c214ff7a (patch) | |
tree | 67432abfa9a27ef12d2ca3ce6a0cdc2fc68f9590 | |
parent | 413ebdb1af6fb0d81845b61254daf02ba0449afd (diff) |
Implement a hack intended to allow Clang to parse libstdc++ 4.5's
headers, which use C++0x generalized initializer lists. Per PR7069, it
appears that the only use is as the return type of a function, so this
commit enables this extension just in that narrow case. If it's enough
for libstdc++ 4.5, or if it can be trivially extended to work with
libstdc++ 4.5, we'll keep it. Otherwise, or if this breaks anything,
we'll revert and wait for the real feature.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127507 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticParseKinds.td | 3 | ||||
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 11 | ||||
-rw-r--r-- | test/SemaCXX/cxx0x-return-init-list.cpp | 18 |
3 files changed, 31 insertions, 1 deletions
diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index f36d74645c..0f011f5741 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -178,6 +178,9 @@ def ext_ref_qualifier : ExtWarn< "reference qualifiers on functions are a C++0x extension">, InGroup<CXX0x>; def ext_inline_namespace : ExtWarn< "inline namespaces are a C++0x feature">, InGroup<CXX0x>; +def ext_generalized_initializer_lists : ExtWarn< + "generalized initializer lists are a C++0x extension unsupported in Clang">, + InGroup<CXX0x>; def err_argument_required_after_attribute : Error< "argument required after attribute">; def err_missing_param : Error<"expected parameter declarator">; diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index d1376accca..d7e9070520 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -1267,7 +1267,16 @@ StmtResult Parser::ParseReturnStatement(ParsedAttributes &attrs) { return StmtError(); } - R = ParseExpression(); + // FIXME: This is a hack to allow something like C++0x's generalized + // initializer lists, but only enough of this feature to allow Clang to + // parse libstdc++ 4.5's headers. + if (Tok.is(tok::l_brace) && getLang().CPlusPlus) { + R = ParseInitializer(); + if (R.isUsable() && !getLang().CPlusPlus0x) + Diag(R.get()->getLocStart(), diag::ext_generalized_initializer_lists) + << R.get()->getSourceRange(); + } else + R = ParseExpression(); if (R.isInvalid()) { // Skip to the semicolon, but don't consume it. SkipUntil(tok::semi, false, true); return StmtError(); diff --git a/test/SemaCXX/cxx0x-return-init-list.cpp b/test/SemaCXX/cxx0x-return-init-list.cpp new file mode 100644 index 0000000000..2005a7f9f6 --- /dev/null +++ b/test/SemaCXX/cxx0x-return-init-list.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// This test checks for a teeny tiny subset of the functionality in +// the C++0x generalized initializer lists feature, which happens to +// be used in libstdc++ 4.5. We accept only this syntax so that Clang +// can handle the libstdc++ 4.5 headers. + +int test0(int i) { + return { i }; // expected-warning{{generalized initializer lists are a C++0x extension unsupported in Clang}} +} + +template<typename T, typename U> +T test1(U u) { + return { u }; // expected-warning{{generalized initializer lists are a C++0x extension unsupported in Clang}} +} + +template int test1(char); +template long test1(int); |