[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-03-11 Thread Vlad Serebrennikov via cfe-commits
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/124844 >From da30f708caee020677675277673e0b7c6f9c644f Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Fri, 24 Jan 2025 15:15:17 +0400 Subject: [PATCH 01/15] [clang] Diagnose default arguments defined in differe

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread Vlad Serebrennikov via cfe-commits
Endilll wrote: During offline discussion with Corentin he pointed out that [over.match.best]/4 talks about multiple declarations that are _found_, and not simply reachable, like my implementation currently assumes. I'll update it to take the results of name lookup into account. https://github

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread via cfe-commits
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/124844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread Vlad Serebrennikov via cfe-commits
@@ -73,6 +73,11 @@ C++17 Feature Support Resolutions to C++ Defect Reports ^ +- Clang now diagnoses ambiguous default arguments declared in different scopes + when calling functions, implementing [over.match.best] p4. + (`CWG1: What if two usi

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread Vlad Serebrennikov via cfe-commits
@@ -27,3 +27,23 @@ extern double(*func2)( P_1(int u) P_1(int v) // expected-error {{too many function parameters; subsequent parameters will be ignored}} int w); + +#define PD_10(x) x, x, x, x, x, x, x, x, x, x, +#define PD_100(x) PD_10(x) PD_10(x) PD_10(x) PD_10

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread Vlad Serebrennikov via cfe-commits
@@ -10960,6 +10960,10 @@ OverloadCandidateSet::BestViableFunction(Sema &S, SourceLocation Loc, S.diagnoseEquivalentInternalLinkageDeclarations(Loc, Best->Function, EquivalentCands); + // [over.match.best]/4 is checked f

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread Vlad Serebrennikov via cfe-commits
@@ -488,6 +490,20 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, continue; } +if (PrevForDefaultArgs->getLexicalDeclContext()->getPrimaryContext() != +ScopeDC->getPrimaryContext() && +!New->isCXXClassMember()) +

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread via cfe-commits
https://github.com/cor3ntin commented: Thanks for working on this, I left a few comments https://github.com/llvm/llvm-project/pull/124844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commit

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread via cfe-commits
@@ -488,6 +490,20 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, continue; } +if (PrevForDefaultArgs->getLexicalDeclContext()->getPrimaryContext() != +ScopeDC->getPrimaryContext() && +!New->isCXXClassMember()) +

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread via cfe-commits
@@ -10960,6 +10960,10 @@ OverloadCandidateSet::BestViableFunction(Sema &S, SourceLocation Loc, S.diagnoseEquivalentInternalLinkageDeclarations(Loc, Best->Function, EquivalentCands); + // [over.match.best]/4 is checked f

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread via cfe-commits
@@ -73,6 +73,11 @@ C++17 Feature Support Resolutions to C++ Defect Reports ^ +- Clang now diagnoses ambiguous default arguments declared in different scopes + when calling functions, implementing [over.match.best] p4. + (`CWG1: What if two usi

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread via cfe-commits
@@ -5810,6 +5810,62 @@ static bool isParenthetizedAndQualifiedAddressOfExpr(Expr *Fn) { return false; } +/// @brief Checks that each default argument needed to make the call +/// is defined only once, implementing [over.match.best]/4 rule. +/// +/// @param FDecl Function de

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread via cfe-commits
@@ -27,3 +27,23 @@ extern double(*func2)( P_1(int u) P_1(int v) // expected-error {{too many function parameters; subsequent parameters will be ignored}} int w); + +#define PD_10(x) x, x, x, x, x, x, x, x, x, x, +#define PD_100(x) PD_10(x) PD_10(x) PD_10(x) PD_10

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread via cfe-commits
@@ -488,6 +490,20 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, continue; } +if (PrevForDefaultArgs->getLexicalDeclContext()->getPrimaryContext() != +ScopeDC->getPrimaryContext() && +!New->isCXXClassMember()) +

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread via cfe-commits
@@ -5810,6 +5810,62 @@ static bool isParenthetizedAndQualifiedAddressOfExpr(Expr *Fn) { return false; } +/// @brief Checks that each default argument needed to make the call +/// is defined only once, implementing [over.match.best]/4 rule. +/// +/// @param FDecl Function de

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread via cfe-commits
@@ -10960,6 +10960,10 @@ OverloadCandidateSet::BestViableFunction(Sema &S, SourceLocation Loc, S.diagnoseEquivalentInternalLinkageDeclarations(Loc, Best->Function, EquivalentCands); + // [over.match.best]/4 is checked f

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread via cfe-commits
@@ -5145,6 +5145,10 @@ def err_addr_ovl_not_func_ptrref : Error< def err_addr_ovl_no_qualifier : Error< "cannot form member pointer of type %0 without '&' and class name">; +def err_ovl_ambiguous_default_arg +: Error<"function call relies on ambiguous default argument %s

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread via cfe-commits
@@ -488,6 +490,20 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, continue; } +if (PrevForDefaultArgs->getLexicalDeclContext()->getPrimaryContext() != +ScopeDC->getPrimaryContext() && +!New->isCXXClassMember()) +

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-29 Thread via cfe-commits
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/124844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-28 Thread Vlad Serebrennikov via cfe-commits
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/124844 >From da30f708caee020677675277673e0b7c6f9c644f Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Fri, 24 Jan 2025 15:15:17 +0400 Subject: [PATCH 01/14] [clang] Diagnose default arguments defined in differe

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-28 Thread Vlad Serebrennikov via cfe-commits
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/124844 >From da30f708caee020677675277673e0b7c6f9c644f Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Fri, 24 Jan 2025 15:15:17 +0400 Subject: [PATCH 01/13] [clang] Diagnose default arguments defined in differe

[clang] [clang] Diagnose default arguments defined in different scopes (PR #124844)

2025-01-28 Thread Vlad Serebrennikov via cfe-commits
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/124844 This patch implements the rule described in N5001.[[over.match.best]/4](https://eel.is/c++draft/over.match.best#general-4): > If the best viable function resolves to a function for which multiple > declarations