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 with deduced type fails when accessing member #39011

Closed
llvmbot opened this issue Nov 14, 2018 · 6 comments
Closed
Labels
bugzilla Issues migrated from bugzilla c++17 duplicate Resolved as duplicate

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 14, 2018

Bugzilla Link 39663
Resolution DUPLICATE
Resolved on Oct 15, 2020 17:45
Version 7.0
OS All
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@erichkeane,@lurkertech,@zygoloid

Extended Description

Try to compile the following c++ program:

template
struct C {
C(T) {}
int a;
};

template
int foo(T v) {
return C{v}.a; // <----
}

int main() {
foo(4);
}

The line marked above fails with the error:

error: member reference base type 'C' is not a structure or union
return (C{v}).a;
~~~~~~^~

Note that the following all work fine:

template
C foo(T v) {
return C{v};
}

and

int foo(int v) {
return C{v}.a;
}

and

C{4}.a;

I tried this also on a recent trunk build (trunk 346600)

@llvmbot
Copy link
Collaborator Author

llvmbot commented Nov 14, 2018

Sorry, for the last example of what works I meant:

template
int foo(T v) {
return C{4}.a;
}

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Nov 14, 2018

Confirmed, presumably we are incorrectly concluding that the dependent non-deduced type C cannot possibly be a class type.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Sep 10, 2019

A coworker of mine just came across the same issue. I have another set of repros and a few cases that do work as expected. I've tested and reproduced the same error back to Clang 5.0 and through until trunk as of today. Interestingly enough it occurs during parsing and not during template instantiation.

template
struct S
{
S(T t) : t(t) {}
T t;
};

template
void good1(T v)
{
(void)S(v);
}

template
void good2(T v)
{
auto s = S(v);
(void)s.t;
}

void good3()
{
(void)[](int v) { (void)S(v).t; };
}

void good4()
{
(void)S(42).t;
}

void good5()
{
(void) { (void)S(42).t; };
}

template
void bad1(T v)
{
// fails with:
// error: member reference base type 'S' is not a structure or union
(void)S(v).t;
}

void bad2()
{
// fails with:
// error: member reference base type 'S' is not a structure or union
(void)[](auto v) { (void)S(v).t; };
}

@erichkeane
Copy link
Collaborator

Looks like this has been fixed? The repro at least no longer does in Trunk: https://godbolt.org/z/jofz6e

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Oct 16, 2020

Yes, fixed under duplicate llvm/llvm-bugzilla-archive#47175 .

*** This bug has been marked as a duplicate of bug llvm/llvm-bugzilla-archive#47175 ***

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Nov 27, 2021

mentioned in issue llvm/llvm-bugzilla-archive#47175

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
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 duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

2 participants