summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/function-redecl.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [SemaCXX] Param diagnostic matches overload logicBrian Gesiak2019-02-011-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Given the following test program: ``` class C { public: int A(int a, int& b); }; int C::A(const int a, int b) { return a * b; } ``` Clang would produce an error message that correctly diagnosed the redeclaration of `C::A` to not match the original declaration (the parameters to the two declarations do not match -- the original takes an `int &` as its 2nd parameter, but the redeclaration takes an `int`). However, it also produced a note diagnostic that inaccurately pointed to the first parameter, claiming that `const int` in the redeclaration did not match the unqualified `int` in the original. The diagnostic is misleading because it has nothing to do with why the program does not compile. The logic for checking for a function overload, in `Sema::FunctionParamTypesAreEqual`, discards cv-qualifiers before checking whether the types are equal. Do the same when producing the overload diagnostic. Reviewers: rsmith Reviewed By: rsmith Subscribers: cpplearner, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57032 llvm-svn: 352831
* Functions declared in a scope should not hide previous declaration in ↵Olivier Goffart2016-06-161-1/+8
| | | | | | | | | | | | | | | | | | | | | earlier scopes This code should be an error: void foo(int); void f3() { int foo(float); { float foo(int); // expected-error {{functions that differ only in their return type cannot be overloaded}} } } the foo(float) function declared at function scope should not hide the float(int) while trying to redeclare functions. Differential Revision: http://reviews.llvm.org/D19763 llvm-svn: 272961
* Switch the semantic DeclContext for a block-scope declaration of a function orRichard Smith2013-09-201-5/+2
| | | | | | | | | | | | | | variable from being the function to being the enclosing namespace scope (in C++) or the TU (in C). This allows us to fix a selection of related issues where we would build incorrect redeclaration chains for such declarations, and fail to notice type mismatches. Such declarations are put into a new IdentifierNamespace, IDNS_LocalExtern, which is only found when searching scopes, and not found when searching DeclContexts. Such a declaration is only made visible in its DeclContext if there are no non-LocalExtern declarations. llvm-svn: 191064
* Fix implementation of C11 6.2.7/4 and C++11 [dcl.array]p3:Richard Smith2013-08-131-8/+13
| | | | | | | | | | | | | When a local extern declaration redeclares some other entity, the type of that entity is merged with the prior type if the prior declaration is visible (in C) or is declared in the same scope (in C++). - Make LookupRedeclarationWithLinkage actually work in C++, use it in the right set of cases, and make it track whether it found a shadowed declaration. - Track whether we found a declaration in the same scope (for C++) including across serialization and template instantiation. llvm-svn: 188307
* Move the extern "C" sema tests to a new file.Rafael Espindola2013-03-121-45/+0
| | | | llvm-svn: 176888
* We already reported an error forRafael Espindola2013-03-121-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | extern "C" { void test5_f() { extern int test5_b; } } static float test5_b; This patch makes us report one for extern "C" { void test6_f() { extern int test6_b; } } extern "C" { static float test6_b; } Not because we think the declaration would be extern C, but because of the rule: An entity with C language linkage shall not be declared with the same name as an entity in global scope... We were just not looking past the extern "C" to see if the decl was in global scope. llvm-svn: 176875
* Error if an extern C declaration matches a previous hidden extern C declaration.Rafael Espindola2013-03-121-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | Without this patch we produce an error for extern "C" { void f() { extern int b; } } extern "C" { extern float b; } but not for extern "C" { void f() { extern int b; } } extern "C" { float b; } llvm-svn: 176867
* Reject incompatible redeclarations of extern C symbols.Rafael Espindola2013-01-111-0/+18
| | | | | | | Before we were only checking if the new declaration itself was marked extern C. Fixes prpr14766. llvm-svn: 172243
* Ignore corrections to functions with bodies when deciding whichKaelyn Uhrain2012-06-071-5/+23
| | | | | | correction to use for an invalid function redeclaration. llvm-svn: 158177
* Remove more redundant lookups. Add a new "all_lookups_iterator" which providesNick Lewycky2012-04-031-2/+5
| | | | | | | | a view over the contents of a DeclContext without exposing the implementation details of the StoredDeclsMap. Use this in LookupVisibleDecls to find the visible declarations. Fixes PR12339! llvm-svn: 153970
* Only accept a typo correction if it doesn't trigger additional errorsKaelyn Uhrain2011-10-111-1/+4
| | | | llvm-svn: 141609
* Give nicer note when a member redeclaration has or lacks 'const'Kaelyn Uhrain2011-10-101-1/+14
| | | | llvm-svn: 141555
* Plug an abstraction leak and fix a crasher in DiagnoseInvalidRedeclarationKaelyn Uhrain2011-09-141-0/+9
| | | | llvm-svn: 139718
* Fix an incorrect note.Matt Beaumont-Gay2011-08-231-0/+16
| | | | | | | | For the test case added to function-redecl.cpp, we were previously complaining about a mismatch in the parameter types, since the definition used the typedef'd type. llvm-svn: 138318
* Don't accept a typo correction if the corrected identifier is the same as theKaelyn Uhrain2011-08-181-0/+4
| | | | | | uncorrected identifier. Fixes a problem pointed out by Eli. llvm-svn: 137987
* Rework DiagnoseInvalidRedeclaration to add the ability to correct typos whenKaelyn Uhrain2011-08-181-0/+26
| | | | | | diagnosing invalid function redeclarations. llvm-svn: 137966
* Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.Daniel Dunbar2009-12-151-1/+1
| | | | | | | | | - This is designed to make it obvious that %clang_cc1 is a "test variable" which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it can be useful to redefine what gets run as 'clang -cc1' (for example, to set a default target). llvm-svn: 91446
* Rename clang to clang-cc.Daniel Dunbar2009-03-241-1/+1
| | | | | | Tests and drivers updated, still need to shuffle dirs. llvm-svn: 67602
* Improve merging of function declarations. Specifically:Douglas Gregor2009-02-241-0/+26
- When we are declaring a function in local scope, we can merge with a visible declaration from an outer scope if that declaration refers to an entity with linkage. This behavior now works in C++ and properly ignores entities without linkage. - Diagnose the use of "static" on a function declaration in local scope. - Diagnose the declaration of a static function after a non-static declaration of the same function. - Propagate the storage specifier to a function declaration from a prior declaration (PR3425) - Don't name-mangle "main" llvm-svn: 65360
OpenPOWER on IntegriCloud