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

Class template argument deduction fails in case of function type argument #51710

Closed
llvmbot opened this issue Oct 31, 2021 · 5 comments · Fixed by #78159
Closed

Class template argument deduction fails in case of function type argument #51710

llvmbot opened this issue Oct 31, 2021 · 5 comments · Fixed by #78159
Assignees
Labels
bugzilla Issues migrated from bugzilla c++17 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 31, 2021

Bugzilla Link 52368
Version trunk
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@zygoloid

Extended Description

In the following program Clang is unable to perform class template argument deduction:

template<typename T>
struct A{
    A(T f()){ f(); }
};

int foo() { return 1; }

int main() {
    [[maybe_unused]] A y = foo; // Clang error
}

GCC accepts it successfully, demo: https://gcc.godbolt.org/z/PKe6T5aW5

Related discussion: https://stackoverflow.com/q/69778510/7325599

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@Endilll
Copy link
Contributor

Endilll commented Jan 14, 2024

Clang behaves as expected if user-provided deduction guide written after http://eel.is/c++draft/over.match.class.deduct#1.1 is present: https://godbolt.org/z/3o367Wz9x

@Endilll Endilll added c++17 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party and removed c++ labels Jan 14, 2024
@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 14, 2024

@llvm/issue-subscribers-c-17

Author: None (llvmbot)

| | | | --- | --- | | Bugzilla Link | [52368](https://llvm.org/bz52368) | | Version | trunk | | OS | Windows NT | | Reporter | LLVM Bugzilla Contributor | | CC | @DougGregor,@zygoloid |

Extended Description

In the following program Clang is unable to perform class template argument deduction:

template&lt;typename T&gt;
struct A{
    A(T f()){ f(); }
};

int foo() { return 1; }

int main() {
    [[maybe_unused]] A y = foo; // Clang error
}

GCC accepts it successfully, demo: https://gcc.godbolt.org/z/PKe6T5aW5

Related discussion: https://stackoverflow.com/q/69778510/7325599

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 14, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (llvmbot)

| | | | --- | --- | | Bugzilla Link | [52368](https://llvm.org/bz52368) | | Version | trunk | | OS | Windows NT | | Reporter | LLVM Bugzilla Contributor | | CC | @DougGregor,@zygoloid |

Extended Description

In the following program Clang is unable to perform class template argument deduction:

template&lt;typename T&gt;
struct A{
    A(T f()){ f(); }
};

int foo() { return 1; }

int main() {
    [[maybe_unused]] A y = foo; // Clang error
}

GCC accepts it successfully, demo: https://gcc.godbolt.org/z/PKe6T5aW5

Related discussion: https://stackoverflow.com/q/69778510/7325599

@Endilll
Copy link
Contributor

Endilll commented Jan 14, 2024

CC @erichkeane

@hokein
Copy link
Collaborator

hokein commented Jan 15, 2024

From the diagnostic message:

:3:5: note: candidate template ignored: could not match 'T ()' against 'int (*)()'

and the AST for the implicitly-generated deduction guide from the explicit constructor:

-FunctionTemplateDecl 0xc82ed58 <line:1:1, line:3:20> col:5 implicit <deduction guide for A>
| |-TemplateTypeParmDecl 0xc80f688 <line:1:10, col:19> col:19 referenced typename depth 0 index 0 T
| `-CXXDeductionGuideDecl 0xc82ec90 <line:3:5, col:20> col:5 implicit <deduction guide for A> 'auto (T (*)()) -> A<T>'
|   `-ParmVarDecl 0xc8103c0 <col:7, col:11> col:9 f 'T ()'

The type for the ParaVarDecl is T (), which doesn't seem correct, it should be a function pointer. We probably miss the decay case when transforming the constructor decl.

@hokein hokein self-assigned this Jan 15, 2024
hokein added a commit to hokein/llvm-project that referenced this issue Jan 15, 2024
hokein added a commit that referenced this issue Jan 16, 2024
…#78159)

Fixes #51710.

When transforming a constructor into a corresponding deduction guide,
the decayed types (function/array type) were not handled properly which
made clang fail to compile valid code. The patch teaches clang handle
these decayed type in the transformation.
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this issue Jan 28, 2024
…llvm#78159)

Fixes llvm#51710.

When transforming a constructor into a corresponding deduction guide,
the decayed types (function/array type) were not handled properly which
made clang fail to compile valid code. The patch teaches clang handle
these decayed type in the transformation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++17 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants