diff options
author | Anders Carlsson <andersca@mac.com> | 2009-06-06 04:14:07 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-06-06 04:14:07 +0000 |
commit | ae0b4e7be78cf0dc2a6a333e865c2be9265774f9 (patch) | |
tree | 8423f379f4b7dde4a825367913af883012669f71 | |
parent | 17d2e3a7d15dc809a25896973d4aa2205e63c122 (diff) |
Make ParmVarDecl::getDefaultArg() more robust, it now asserts that the argument is not unparsed. Add a new hasDefaultArg() and use it in places where getDefaultArg() was called when the argument was unparsed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72984 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Decl.h | 16 | ||||
-rw-r--r-- | lib/AST/Decl.cpp | 2 | ||||
-rw-r--r-- | lib/AST/DeclCXX.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 2 |
4 files changed, 18 insertions, 6 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index e134aed73d..7440e7b5f1 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -515,10 +515,22 @@ public: objcDeclQualifier = QTVal; } - const Expr *getDefaultArg() const { return DefaultArg; } - Expr *getDefaultArg() { return DefaultArg; } + const Expr *getDefaultArg() const { + assert(!hasUnparsedDefaultArg() && "Default argument is not yet parsed!"); + return DefaultArg; + } + Expr *getDefaultArg() { + assert(!hasUnparsedDefaultArg() && "Default argument is not yet parsed!"); + return DefaultArg; + } void setDefaultArg(Expr *defarg) { DefaultArg = defarg; } + /// hasDefaultArg - Determines whether this parameter has a default argument, + /// either parsed or not. + bool hasDefaultArg() const { + return DefaultArg != 0; + } + /// hasUnparsedDefaultArg - Determines whether this parameter has a /// default argument that has not yet been parsed. This will occur /// during the processing of a C++ class whose member functions have diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index cb3ec1f487..dfec1061c2 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -489,7 +489,7 @@ void FunctionDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo, unsigned FunctionDecl::getMinRequiredArguments() const { unsigned NumRequiredArgs = getNumParams(); while (NumRequiredArgs > 0 - && getParamDecl(NumRequiredArgs-1)->getDefaultArg()) + && getParamDecl(NumRequiredArgs-1)->hasDefaultArg()) --NumRequiredArgs; return NumRequiredArgs; diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 19f8958277..94daf48445 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -326,7 +326,7 @@ CXXConstructorDecl::isCopyConstructor(ASTContext &Context, // const volatile X&, and either there are no other parameters // or else all other parameters have default arguments (8.3.6). if ((getNumParams() < 1) || - (getNumParams() > 1 && getParamDecl(1)->getDefaultArg() == 0)) + (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg())) return false; const ParmVarDecl *Param = getParamDecl(0); @@ -363,7 +363,7 @@ bool CXXConstructorDecl::isConvertingConstructor() const { return (getNumParams() == 0 && getType()->getAsFunctionProtoType()->isVariadic()) || (getNumParams() == 1) || - (getNumParams() > 1 && getParamDecl(1)->getDefaultArg() != 0); + (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg()); } CXXDestructorDecl * diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index f13179f043..b59ac879d1 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -1357,7 +1357,7 @@ void Sema::CheckConstructor(CXXConstructorDecl *Constructor) { if (!Constructor->isInvalidDecl() && ((Constructor->getNumParams() == 1) || (Constructor->getNumParams() > 1 && - Constructor->getParamDecl(1)->getDefaultArg() != 0))) { + Constructor->getParamDecl(1)->hasDefaultArg()))) { QualType ParamType = Constructor->getParamDecl(0)->getType(); QualType ClassTy = Context.getTagDeclType(ClassDecl); if (Context.getCanonicalType(ParamType).getUnqualifiedType() == ClassTy) { |