summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2012-12-28 14:21:58 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2012-12-28 14:21:58 +0000
commit576127d90e242b8a6de7710794cdc4c146891229 (patch)
tree8865b7f6bb0b903958f4ad2dbf8ad148bf79b349 /clang/lib/Sema/SemaDecl.cpp
parent9e575dafad8d9f72a839a596dea361fedb544afd (diff)
downloadbcm5719-llvm-576127d90e242b8a6de7710794cdc4c146891229.tar.gz
bcm5719-llvm-576127d90e242b8a6de7710794cdc4c146891229.zip
Reject overloading of two static extern C functions.
This patch moves hasCLanguageLinkage to be VarDecl and FunctionDecl methods so that they can be used from SemaOverload.cpp and then fixes the logic in Sema::IsOverload. llvm-svn: 171193
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp30
1 files changed, 2 insertions, 28 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 7c193e13bd4..c9d0c7750c6 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1969,32 +1969,6 @@ static bool isABIDefaultCC(Sema &S, CallingConv CC, FunctionDecl *D) {
return ABIDefaultCC == CC;
}
-/// Check if the given decl has C language linkage. Note that this is not
-/// the same as D.isExternC() since decls with non external linkage can have C
-/// language linkage. They can also have C language linkage when they are
-/// not declared in an extern C context, but a previous decl is.
-template<typename T>
-bool hasCLanguageLinkage(const T &D) {
- // Language linkage is a C++ concept, but saying that everything in C has
- // C language linkage fits the implementation nicelly.
- ASTContext &Context = D.getASTContext();
- if (!Context.getLangOpts().CPlusPlus)
- return true;
-
- // dcl.link 4: A C language linkage is ignored in determining the language
- // linkage of the names of class members and the function type of class member
- // functions.
- const DeclContext *DC = D.getDeclContext();
- if (DC->isRecord())
- return false;
-
- // If the first decl is in an extern "C" context, any other redeclaration
- // will have C language linkage. If the first one is not in an extern "C"
- // context, we would have reported an error for any other decl being in one.
- const T *First = D.getFirstDeclaration();
- return First->getDeclContext()->isExternCContext();
-}
-
/// MergeFunctionDecl - We just parsed a function 'New' from
/// declarator D which has the same name and scope as a previous
/// declaration 'Old'. Figure out how to resolve this situation,
@@ -2255,7 +2229,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD, Scope *S) {
assert(OldQTypeForComparison.isCanonical());
}
- if (!hasCLanguageLinkage(*Old) && hasCLanguageLinkage(*New)) {
+ if (!Old->hasCLanguageLinkage() && New->hasCLanguageLinkage()) {
Diag(New->getLocation(), diag::err_different_language_linkage) << New;
Diag(Old->getLocation(), PrevDiag);
return true;
@@ -2645,7 +2619,7 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
return;
}
- if (!hasCLanguageLinkage(*Old) && hasCLanguageLinkage(*New)) {
+ if (!Old->hasCLanguageLinkage() && New->hasCLanguageLinkage()) {
Diag(New->getLocation(), diag::err_different_language_linkage) << New;
Diag(Old->getLocation(), diag::note_previous_definition);
New->setInvalidDecl();
OpenPOWER on IntegriCloud