Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static and non-static member function templates with the same parameter types are accepted #52951

Closed
Fedr opened this issue Jan 2, 2022 · 8 comments
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" invalid Resolved as invalid, i.e. not a bug

Comments

@Fedr
Copy link

Fedr commented Jan 2, 2022

This code

struct A {
    static int f(auto) { return 1; }
    int f(auto) requires true { return 2; }
};

is invalid per https://timsong-cpp.github.io/cppwp/n4861/class.static.mfct#2:

There shall not be a static and a non-static member function with the same name and the same parameter types ([over.load]).

But Clang accepts it without a warning (as some other compilers do), which later produces confusing errors. Related discussion: https://stackoverflow.com/q/70542265/7325599

@Endilll Endilll added c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Sep 20, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 20, 2023

@llvm/issue-subscribers-c-20

This code ``` struct A { static int f(auto) { return 1; } int f(auto) requires true { return 2; } }; ``` is invalid per https://timsong-cpp.github.io/cppwp/n4861/class.static.mfct#2: > There shall not be a static and a non-static member function with the same name and the same parameter types ([over.load]).

But Clang accepts it without a warning (as some other compilers do), which later produces confusing errors. Related discussion: https://stackoverflow.com/q/70542265/7325599

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 20, 2023

@llvm/issue-subscribers-clang-frontend

This code ``` struct A { static int f(auto) { return 1; } int f(auto) requires true { return 2; } }; ``` is invalid per https://timsong-cpp.github.io/cppwp/n4861/class.static.mfct#2: > There shall not be a static and a non-static member function with the same name and the same parameter types ([over.load]).

But Clang accepts it without a warning (as some other compilers do), which later produces confusing errors. Related discussion: https://stackoverflow.com/q/70542265/7325599

@Endilll
Copy link
Contributor

Endilll commented Sep 20, 2023

Referenced note was modified to exclude quoted sentence in P1787R6 Declarations and where to find them. I'm not sure what is the normative wording for this.
We still don't issue any relevant diagnostics: https://godbolt.org/z/5abKvYG3n
But with main not commented out, we've been issuing an error about identical mangling those two functions have.
So this might be related to itanium-cxx-abi/cxx-abi#24

@cor3ntin
Copy link
Contributor

Not a bug
https://compiler-explorer.com/z/Tso6G5xMq

http://eel.is/c++draft/basic#scope.scope-4.3

Two function or function template declarations declare corresponding overloads if:

  • both declare functions with the same non-object-parameter-type-list,18 equivalent ([temp.over.link]) trailing requires
    clauses
    (if any, except as specified in [temp.friend]), and ...

@Endilll is correct this was changed by P1787, and a whole bunch of subsequent papers pertaining to deducing this. but notably, P1787 was applied as a DR

Removing the require makes the definition correspond https://compiler-explorer.com/z/sY6hdTzoK

@Endilll Endilll added the invalid Resolved as invalid, i.e. not a bug label Sep 20, 2023
@Endilll Endilll closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2023
@shafik
Copy link
Collaborator

shafik commented Sep 20, 2023

So this related code definitely shows an issue: https://gcc.godbolt.org/z/aYK8Y31d4

struct A {
    static int f(auto) { return 1; }
    int f(auto) requires true { return 2; }
};

int main() {
    [[maybe_unused]] int (A::*y)(int) = &A::f; // ok everywhere (if no below line)
    [[maybe_unused]] int (*x)(int) = &A::f; //ok in GCC and Clang (if no above line)
}

but I believe this would then be: #49884

@shafik
Copy link
Collaborator

shafik commented Sep 20, 2023

CC @zygoloid @hubert-reinterpretcast should this example I posted just before this be ambiguous? After reading expr.unary p6 and over.over p6 I think this should be valid but wanted confirmation.

@cor3ntin
Copy link
Contributor

@shafik I believe that case is https://eel.is/c++draft/over.over#4 specifically

y selects the second overload because the target type is a PMF, and x the first because the target type is a function pointer.
Not sure what is going on with mangling though

@zygoloid
Copy link
Collaborator

Fixed in trunk by 4b163e3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" invalid Resolved as invalid, i.e. not a bug
Projects
Status: Done
Development

No branches or pull requests

6 participants