aboutsummaryrefslogtreecommitdiff
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
commit83913e36c847052966d9ff60d760ea7231ed8b6b (patch)
tree2a81a1391f5542ea6b768ef44e62e42356d30167
parentf177a8df322f463fd382fb1588a27308fa728d34 (diff)
When creating function types, remove any top-level CVR qualifications in the function type argument types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82093 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/ASTContext.cpp6
-rw-r--r--lib/Sema/Sema.h13
-rw-r--r--lib/Sema/SemaType.cpp11
-rw-r--r--test/CXX/dcl.decl/dcl.meaning/dcl.fct/p3.cpp3
4 files changed, 29 insertions, 4 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 84a5195a60..f701ae4732 100644
--- a/lib/AST/ASTContext.cpp
+++ b/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/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 802dab29d0..3e99871dd1 100644
--- a/lib/Sema/Sema.h
+++ b/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/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index bbcb1a4689..a56e1ae7b2 100644
--- a/lib/Sema/SemaType.cpp
+++ b/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/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p3.cpp b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p3.cpp
new file mode 100644
index 0000000000..6f71978c4e
--- /dev/null
+++ b/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