[cfe-commits] r70022 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp test/SemaCXX/conversion-function.cpp
Chris Lattner
sabre at nondot.org
Sat Apr 25 01:35:12 PDT 2009
Author: lattner
Date: Sat Apr 25 03:35:12 2009
New Revision: 70022
URL: http://llvm.org/viewvc/llvm-project?rev=70022&view=rev
Log:
change a couple more c++ sema methods to be based on isinvalid bits.
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/conversion-function.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=70022&r1=70021&r2=70022&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sat Apr 25 03:35:12 2009
@@ -1684,10 +1684,10 @@
QualType CheckConstructorDeclarator(Declarator &D, QualType R,
FunctionDecl::StorageClass& SC);
- bool CheckConstructor(CXXConstructorDecl *Constructor);
+ void CheckConstructor(CXXConstructorDecl *Constructor);
QualType CheckDestructorDeclarator(Declarator &D,
FunctionDecl::StorageClass& SC);
- bool CheckConversionDeclarator(Declarator &D, QualType &R,
+ void CheckConversionDeclarator(Declarator &D, QualType &R,
FunctionDecl::StorageClass& SC);
DeclPtrTy ActOnConversionDeclarator(CXXConversionDecl *Conversion);
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=70022&r1=70021&r2=70022&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Apr 25 03:35:12 2009
@@ -2030,16 +2030,14 @@
Diag(D.getIdentifierLoc(),
diag::err_conv_function_not_member);
return 0;
- } else {
- if (!D.isInvalidType())
- D.setInvalidType(CheckConversionDeclarator(D, R, SC));
-
- NewFD = CXXConversionDecl::Create(Context, cast<CXXRecordDecl>(DC),
- D.getIdentifierLoc(), Name, R,
- isInline, isExplicit);
-
- isVirtualOkay = true;
}
+
+ CheckConversionDeclarator(D, R, SC);
+ NewFD = CXXConversionDecl::Create(Context, cast<CXXRecordDecl>(DC),
+ D.getIdentifierLoc(), Name, R,
+ isInline, isExplicit);
+
+ isVirtualOkay = true;
} else if (DC->isRecord()) {
// This is a C++ method declaration.
NewFD = CXXMethodDecl::Create(Context, cast<CXXRecordDecl>(DC),
@@ -2315,8 +2313,7 @@
if (getLangOptions().CPlusPlus) {
// C++-specific checks.
if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(NewFD)) {
- if (CheckConstructor(Constructor))
- return NewFD->setInvalidDecl();
+ CheckConstructor(Constructor);
} else if (isa<CXXDestructorDecl>(NewFD)) {
CXXRecordDecl *Record = cast<CXXRecordDecl>(NewFD->getParent());
Record->setUserDeclaredDestructor(true);
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=70022&r1=70021&r2=70022&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sat Apr 25 03:35:12 2009
@@ -1253,10 +1253,8 @@
// again. It could produce additional diagnostics or affect whether
// the class has implicitly-declared destructors, among other
// things.
- if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(Method)) {
- if (CheckConstructor(Constructor))
- Constructor->setInvalidDecl();
- }
+ if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(Method))
+ CheckConstructor(Constructor);
// Check the default arguments, which we may have added.
if (!Method->isInvalidDecl())
@@ -1334,13 +1332,11 @@
/// CheckConstructor - Checks a fully-formed constructor for
/// well-formedness, issuing any diagnostics required. Returns true if
/// the constructor declarator is invalid.
-bool Sema::CheckConstructor(CXXConstructorDecl *Constructor) {
+void Sema::CheckConstructor(CXXConstructorDecl *Constructor) {
CXXRecordDecl *ClassDecl
= dyn_cast<CXXRecordDecl>(Constructor->getDeclContext());
if (!ClassDecl)
- return true;
-
- bool Invalid = Constructor->isInvalidDecl();
+ return Constructor->setInvalidDecl();
// C++ [class.copy]p3:
// A declaration of a constructor for a class X is ill-formed if
@@ -1357,14 +1353,12 @@
SourceLocation ParamLoc = Constructor->getParamDecl(0)->getLocation();
Diag(ParamLoc, diag::err_constructor_byvalue_arg)
<< CodeModificationHint::CreateInsertion(ParamLoc, " const &");
- Invalid = true;
+ Constructor->setInvalidDecl();
}
}
// Notify the class that we've added a constructor.
ClassDecl->addedConstructor(Context, Constructor);
-
- return Invalid;
}
/// CheckDestructorDeclarator - Called by ActOnDeclarator to check
@@ -1460,22 +1454,21 @@
/// will emit diagnostics and return true. Otherwise, it will return
/// false. Either way, the type @p R will be updated to reflect a
/// well-formed type for the conversion operator.
-bool Sema::CheckConversionDeclarator(Declarator &D, QualType &R,
+void Sema::CheckConversionDeclarator(Declarator &D, QualType &R,
FunctionDecl::StorageClass& SC) {
- bool isInvalid = false;
-
// C++ [class.conv.fct]p1:
// Neither parameter types nor return type can be specified. The
// type of a conversion function (8.3.5) is âfunction taking no
// parameter returning conversion-type-id.â
if (SC == FunctionDecl::Static) {
- Diag(D.getIdentifierLoc(), diag::err_conv_function_not_member)
- << "static" << SourceRange(D.getDeclSpec().getStorageClassSpecLoc())
- << SourceRange(D.getIdentifierLoc());
- isInvalid = true;
+ if (!D.isInvalidType())
+ Diag(D.getIdentifierLoc(), diag::err_conv_function_not_member)
+ << "static" << SourceRange(D.getDeclSpec().getStorageClassSpecLoc())
+ << SourceRange(D.getIdentifierLoc());
+ D.setInvalidType();
SC = FunctionDecl::None;
}
- if (D.getDeclSpec().hasTypeSpecifier()) {
+ if (D.getDeclSpec().hasTypeSpecifier() && !D.isInvalidType()) {
// Conversion functions don't have return types, but the parser will
// happily parse something like:
//
@@ -1495,11 +1488,14 @@
// Delete the parameters.
D.getTypeObject(0).Fun.freeArgs();
+ D.setInvalidType();
}
// Make sure the conversion function isn't variadic.
- if (R->getAsFunctionProtoType()->isVariadic())
+ if (R->getAsFunctionProtoType()->isVariadic() && !D.isInvalidType()) {
Diag(D.getIdentifierLoc(), diag::err_conv_function_variadic);
+ D.setInvalidType();
+ }
// C++ [class.conv.fct]p4:
// The conversion-type-id shall not represent a function type nor
@@ -1508,9 +1504,11 @@
if (ConvType->isArrayType()) {
Diag(D.getIdentifierLoc(), diag::err_conv_function_to_array);
ConvType = Context.getPointerType(ConvType);
+ D.setInvalidType();
} else if (ConvType->isFunctionType()) {
Diag(D.getIdentifierLoc(), diag::err_conv_function_to_function);
ConvType = Context.getPointerType(ConvType);
+ D.setInvalidType();
}
// Rebuild the function type "R" without any parameters (in case any
@@ -1524,8 +1522,6 @@
Diag(D.getDeclSpec().getExplicitSpecLoc(),
diag::warn_explicit_conversion_functions)
<< SourceRange(D.getDeclSpec().getExplicitSpecLoc());
-
- return isInvalid;
}
/// ActOnConversionDeclarator - Called by ActOnDeclarator to complete
Modified: cfe/trunk/test/SemaCXX/conversion-function.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conversion-function.cpp?rev=70022&r1=70021&r2=70022&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/conversion-function.cpp (original)
+++ cfe/trunk/test/SemaCXX/conversion-function.cpp Sat Apr 25 03:35:12 2009
@@ -23,8 +23,11 @@
class Y {
public:
void operator bool(int, ...) const; // expected-error{{conversion function cannot have a return type}} \
- // expected-error{{conversion function cannot have any parameters}} \
- // expected-error{{conversion function cannot be variadic}}
+ // expected-error{{conversion function cannot have any parameters}}
+
+ operator float(...) const; // expected-error{{conversion function cannot be variadic}}
+
+
operator func_type(); // expected-error{{conversion function cannot convert to a function type}}
operator array_type(); // expected-error{{conversion function cannot convert to an array type}}
};
More information about the cfe-commits
mailing list