summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-09-16 23:47:08 +0000
committerAnders Carlsson <andersca@mac.com>2009-09-16 23:47:08 +0000
commite7e163cc0b36f4f1f2a5c79a3a9645804a753a2e (patch)
treed6fe5dbd8197ac9f0c073ab983ed263cad8d6c21
parente29f04859b1959de3bef400264eec70ce204460c (diff)
downloadbcm5719-llvm-e7e163cc0b36f4f1f2a5c79a3a9645804a753a2e.tar.gz
bcm5719-llvm-e7e163cc0b36f4f1f2a5c79a3a9645804a753a2e.zip
When creating function types, remove any top-level CVR qualifications in the function type argument types.
llvm-svn: 82093
-rw-r--r--clang/lib/AST/ASTContext.cpp6
-rw-r--r--clang/lib/Sema/Sema.h13
-rw-r--r--clang/lib/Sema/SemaType.cpp11
-rw-r--r--clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p3.cpp3
4 files changed, 29 insertions, 4 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 84a5195a60e..f701ae47320 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1643,6 +1643,12 @@ QualType ASTContext::getFunctionType(QualType ResultTy,const QualType *ArgArray,
unsigned TypeQuals, bool hasExceptionSpec,
bool hasAnyExceptionSpec, unsigned NumExs,
const QualType *ExArray, bool NoReturn) {
+ if (LangOpts.CPlusPlus) {
+ for (unsigned i = 0; i != NumArgs; ++i)
+ assert(!ArgArray[i].getCVRQualifiers() &&
+ "C++ arguments can't have toplevel CVR qualifiers!");
+ }
+
// Unique functions, to guarantee there is only one function of a particular
// structure.
llvm::FoldingSetNodeID ID;
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index 802dab29d01..3e99871dd11 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -3605,6 +3605,19 @@ public:
void DiagnoseMissingMember(SourceLocation MemberLoc, DeclarationName Member,
NestedNameSpecifier *NNS, SourceRange Range);
+ /// adjustFunctionParamType - Converts the type of a function parameter to a
+ // type that can be passed as an argument type to
+ /// ASTContext::getFunctionType.
+ ///
+ /// C++ [dcl.fct]p3: "...Any cv-qualifier modifying a parameter type is
+ /// deleted. Such cv-qualifiers affect only the definition of the parameter
+ /// within the body of the function; they do not affect the function type.
+ QualType adjustFunctionParamType(QualType T) const {
+ if (!Context.getLangOptions().CPlusPlus)
+ return T;
+
+ return T.getUnqualifiedType();
+ }
//===--------------------------------------------------------------------===//
// Extra semantic analysis beyond the C type system
private:
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index bbcb1a46899..a56e1ae7b24 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -692,7 +692,7 @@ QualType Sema::BuildFunctionType(QualType T,
Invalid = true;
}
- ParamTypes[Idx] = ParamType;
+ ParamTypes[Idx] = adjustFunctionParamType(ParamType);
}
if (Invalid)
@@ -1020,8 +1020,11 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) {
ParmVarDecl *Param = FTI.ArgInfo[i].Param.getAs<ParmVarDecl>();
- if (Param)
- ArgTys.push_back(Param->getType());
+ if (Param) {
+ QualType ArgTy = adjustFunctionParamType(Param->getType());
+
+ ArgTys.push_back(ArgTy);
+ }
}
SourceTy = Context.getFunctionType(SourceTy, ArgTys.data(),
ArgTys.size(),
@@ -1144,7 +1147,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
}
}
- ArgTys.push_back(ArgTy);
+ ArgTys.push_back(adjustFunctionParamType(ArgTy));
}
llvm::SmallVector<QualType, 4> Exceptions;
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p3.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p3.cpp
new file mode 100644
index 00000000000..6f71978c4e4
--- /dev/null
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p3.cpp
@@ -0,0 +1,3 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+void f(int) { } // expected-note {{previous definition is here}}
+void f(const int) { } // expected-error {{redefinition of 'f'}} \ No newline at end of file
OpenPOWER on IntegriCloud