aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaType.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-10-24 21:46:40 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-10-24 21:46:40 +0000
commit971c4fae6092976338b755af1d47dac07c8f16e3 (patch)
tree79c99cc3a9071a8d1c7a1a20a22a73dc9ae71d08 /lib/Sema/SemaType.cpp
parentb394d1ca7d6debc1bce0f7797bb790df6bbf1d29 (diff)
-Add support for cv-qualifiers after function declarators.
-Add withConst/withVolatile/withRestrict methods to QualType class, that return the QualType plus the respective qualifier. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58120 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaType.cpp')
-rw-r--r--lib/Sema/SemaType.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index a12ec3ad7c..7bcd1e5765 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -409,7 +409,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
if (getLangOptions().CPlusPlus) {
// C++ 8.3.5p2: If the parameter-declaration-clause is empty, the
// function takes no arguments.
- T = Context.getFunctionType(T, NULL, 0, FTI.isVariadic);
+ T = Context.getFunctionType(T, NULL, 0, FTI.isVariadic,FTI.TypeQuals);
} else {
// Simple void foo(), where the incoming T is the result type.
T = Context.getFunctionTypeNoProto(T);
@@ -482,7 +482,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
ArgTys.push_back(ArgTy);
}
T = Context.getFunctionType(T, &ArgTys[0], ArgTys.size(),
- FTI.isVariadic);
+ FTI.isVariadic, FTI.TypeQuals);
}
break;
}
@@ -491,6 +491,31 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
if (const AttributeList *AL = DeclType.getAttrs())
ProcessTypeAttributeList(T, AL);
}
+
+ if (getLangOptions().CPlusPlus && T->isFunctionType()) {
+ const FunctionTypeProto *FnTy = T->getAsFunctionTypeProto();
+ assert(FnTy && "Why oh why is there not a FunctionTypeProto here ?");
+
+ // C++ 8.3.5p4: A cv-qualifier-seq shall only be part of the function type
+ // for a nonstatic member function, the function type to which a pointer
+ // to member refers, or the top-level function type of a function typedef
+ // declaration.
+ if (FnTy->getTypeQuals() != 0 &&
+ D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef &&
+ (D.getContext() != Declarator::MemberContext ||
+ D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static)) {
+
+ if (D.isFunctionDeclarator())
+ Diag(D.getIdentifierLoc(), diag::err_invalid_qualified_function_type);
+ else
+ Diag(D.getIdentifierLoc(),
+ diag::err_invalid_qualified_typedef_function_type_use);
+
+ // Strip the cv-quals from the type.
+ T = Context.getFunctionType(FnTy->getResultType(), FnTy->arg_type_begin(),
+ FnTy->getNumArgs(), FnTy->isVariadic());
+ }
+ }
// If there were any type attributes applied to the decl itself (not the
// type, apply the type attribute to the type!)