[cfe-commits] r127507 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseStmt.cpp test/SemaCXX/cxx0x-return-init-list.cpp
Douglas Gregor
dgregor at apple.com
Fri Mar 11 15:10:44 PST 2011
Author: dgregor
Date: Fri Mar 11 17:10:44 2011
New Revision: 127507
URL: http://llvm.org/viewvc/llvm-project?rev=127507&view=rev
Log:
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.
Added:
cfe/trunk/test/SemaCXX/cxx0x-return-init-list.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseStmt.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=127507&r1=127506&r2=127507&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Mar 11 17:10:44 2011
@@ -178,6 +178,9 @@
"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">;
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=127507&r1=127506&r2=127507&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Fri Mar 11 17:10:44 2011
@@ -1267,7 +1267,16 @@
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();
Added: cfe/trunk/test/SemaCXX/cxx0x-return-init-list.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-return-init-list.cpp?rev=127507&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-return-init-list.cpp (added)
+++ cfe/trunk/test/SemaCXX/cxx0x-return-init-list.cpp Fri Mar 11 17:10:44 2011
@@ -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);
More information about the cfe-commits
mailing list