]> granicus.if.org Git - clang/commitdiff
When creating function types, remove any top-level CVR qualifications in the function...
authorAnders Carlsson <andersca@mac.com>
Wed, 16 Sep 2009 23:47:08 +0000 (23:47 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 16 Sep 2009 23:47:08 +0000 (23:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82093 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
lib/Sema/Sema.h
lib/Sema/SemaType.cpp
test/CXX/dcl.decl/dcl.meaning/dcl.fct/p3.cpp [new file with mode: 0644]

index 84a5195a60e93d247dd226ec3f5409c530656ff2..f701ae47320dccd9e873e6de1a6f450625e77742 100644 (file)
@@ -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;
index 802dab29d012e7c331afe4345180f00c3582fc9f..3e99871dd118057d2a9d79b1c30162cb7ccf266a 100644 (file)
@@ -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:
index bbcb1a4689907e4cd12c818a029ae3c97f9049e3..a56e1ae7b248febe2c06c899a475e55a4b280b2d 100644 (file)
@@ -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 (file)
index 0000000..6f71978
--- /dev/null
@@ -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