[cfe-commits] r121912 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Sema/Sema.h lib/AST/Type.cpp lib/Sema/SemaDecl.cpp test/CXX/temp/temp.decls/temp.variadic/p5.cpp
Douglas Gregor
dgregor at apple.com
Wed Dec 15 15:18:36 PST 2010
Author: dgregor
Date: Wed Dec 15 17:18:36 2010
New Revision: 121912
URL: http://llvm.org/viewvc/llvm-project?rev=121912&view=rev
Log:
Check for unexpanded parameter packs in various kinds of
declarations. This is a work in progress, as I go through the C++
declaration grammar to identify where unexpanded parameter packs can
occur.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=121912&r1=121911&r2=121912&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Dec 15 17:18:36 2010
@@ -1822,17 +1822,21 @@
"parameter%select{| pack}1 declared here">;
def err_unexpanded_parameter_pack_0 : Error<
- "%select{expression|base type|declaration type|template argument}0 contains "
- "unexpanded parameter pack">;
+ "%select{expression|base type|declaration type|data member type|bit-field "
+ "size}0 "
+ "contains unexpanded parameter pack">;
def err_unexpanded_parameter_pack_1 : Error<
- "%select{expression|base type|declaration type|template argument}0 contains "
- "unexpanded parameter pack %1">;
+ "%select{expression|base type|declaration type|data member type|bit-field "
+ "size}0 "
+ "contains unexpanded parameter pack %1">;
def err_unexpanded_parameter_pack_2 : Error<
- "%select{expression|base type|declaration type|template argument}0 contains "
- "unexpanded parameter packs %1 and %2">;
+ "%select{expression|base type|declaration type|data member type|bit-field "
+ "size}0 "
+ "contains unexpanded parameter packs %1 and %2">;
def err_unexpanded_parameter_pack_3_or_more : Error<
- "%select{expression|base type|declaration type|template argument}0 contains "
- "unexpanded parameter packs %1, %2, ...">;
+ "%select{expression|base type|declaration type|data member type|bit-field "
+ "size}0 "
+ "contains unexpanded parameter packs %1, %2, ...">;
def err_unexpected_typedef : Error<
"unexpected type name %0: expected expression">;
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=121912&r1=121911&r2=121912&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Dec 15 17:18:36 2010
@@ -3135,10 +3135,20 @@
/// Note that the values of this enumeration line up with the first
/// argument to the \c err_unexpanded_parameter_pack diagnostic.
enum UnexpandedParameterPackContext {
+ /// \brief An arbitrary expression.
UPPC_Expression = 0,
+
+ /// \brief The base type of a class type.
UPPC_BaseType,
+
+ /// \brief The type of an arbitrary declaration.
UPPC_DeclarationType,
- UPPC_TemplateArgument
+
+ /// \brief The type of a data member.
+ UPPC_DataMemberType,
+
+ /// \brief The size of a bit-field.
+ UPPC_BitFieldWidth
};
/// \brief If the given type contains an unexpanded parameter pack,
Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=121912&r1=121911&r2=121912&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Wed Dec 15 17:18:36 2010
@@ -1123,8 +1123,15 @@
// Fill in the exception array.
QualType *exnSlot = argSlot + numArgs;
- for (unsigned i = 0, e = epi.NumExceptions; i != e; ++i)
+ for (unsigned i = 0, e = epi.NumExceptions; i != e; ++i) {
+ if (epi.Exceptions[i]->isDependentType())
+ setDependent();
+
+ if (epi.Exceptions[i]->containsUnexpandedParameterPack())
+ setContainsUnexpandedParameterPack();
+
exnSlot[i] = epi.Exceptions[i];
+ }
}
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=121912&r1=121911&r2=121912&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Dec 15 17:18:36 2010
@@ -6424,7 +6424,9 @@
<< FieldName << FieldTy << BitWidth->getSourceRange();
return Diag(FieldLoc, diag::err_not_integral_type_anon_bitfield)
<< FieldTy << BitWidth->getSourceRange();
- }
+ } else if (DiagnoseUnexpandedParameterPack(const_cast<Expr *>(BitWidth),
+ UPPC_BitFieldWidth))
+ return true;
// If the bit-width is type- or value-dependent, don't try to check
// it now.
@@ -6499,9 +6501,17 @@
TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);
QualType T = TInfo->getType();
- if (getLangOptions().CPlusPlus)
+ if (getLangOptions().CPlusPlus) {
CheckExtraCXXDefaultArguments(D);
+ if (DiagnoseUnexpandedParameterPack(D.getIdentifierLoc(), TInfo,
+ UPPC_DataMemberType)) {
+ D.setInvalidType();
+ T = Context.IntTy;
+ TInfo = Context.getTrivialTypeSourceInfo(T, Loc);
+ }
+ }
+
DiagnoseFunctionSpecifiers(D);
if (D.getDeclSpec().isThreadSpecified())
Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p5.cpp?rev=121912&r1=121911&r2=121912&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p5.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p5.cpp Wed Dec 15 17:18:36 2010
@@ -96,11 +96,25 @@
// ObjCObjectPointerType is uninteresting
};
+// FIXME: Test for unexpanded parameter packs in each of the expression nodes.
+
template<typename ... Types>
void TestPPNameFunc(int i) {
f(static_cast<Types>(i)); // expected-error{{expression contains unexpanded parameter pack 'Types'}}
}
+// FIXME: Test for unexpanded parameter packs in declarations.
+template<typename... Types>
+struct TestUnexpandedDecls {
+ void member_function(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
+ void member_function () throw(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
+ Types data_member; // expected-error{{data member type contains unexpanded parameter pack 'Types'}}
+ static Types static_data_member; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
+ unsigned bit_field : static_cast<Types>(0); // expected-error{{bit-field size contains unexpanded parameter pack 'Types'}}
+};
+
+// Test for diagnostics in the presence of multiple unexpanded
+// parameter packs.
template<typename T, typename U> struct pair;
template<typename ...OuterTypes>
@@ -115,3 +129,4 @@
};
};
};
+
More information about the cfe-commits
mailing list