-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
default member initializer for 'm' needed within definition of enclosing class for default argument of function #36032
Comments
I'm curious what MSVC does if the 'double m' initializer uses a static method from later in 'A'. I think that's legal, and that's why our parsing is done in this order. |
I got the same error while trying explicit specialization in class scope (DR727 implemented by Richard Smith in r327705). $ cat > test.cpp
}; int main() { $ clang++ -std=c++17 test.coo Note: The error only happens if Size is 0. Also, the workaround for explicit specialization in class scope...
... compiles without any error. |
Regarding comment#0: if we want to fix this once-and-for-all, we should use the same technique we use for delayed template parsing: teach Sema to call back into the parser to parse the delayed regions on-demand. Then we would only reject the cases where there's an actual dependency cycle. Regarding comment#2: this is a separate bug. Looks like Clang's support for class-scope explicit specializations is broken (despite our exposing it in MSVC-compatible mode for quite some time). We have to mark such specializations as either "implicit instantiation" or "explicit specialization" (not both, because we only have one TemplateSpecializationKind per specialization); both of those options cause some parts of Clang to do the wrong thing. We'll probably need to add a TSK_ImplicitInstantiationOfExplicitSpecialization and wire that through everywhere to make this properly work. |
Hi Richard, tnx for looking into this. That said, I already worked around this by making this 2 functions (1 calling the other with B as extra argument). |
*** Bug llvm/llvm-bugzilla-archive#37235 has been marked as a duplicate of this bug. *** |
Correcting 'enhancement' to 'normal' issue. This ain't a feature request. |
mentioned in issue llvm/llvm-bugzilla-archive#37235 |
This is still broken. Note that it doesn't even need eg:
|
GCC agrees with Clang, so this is truly an MSVC compat only issue |
Or they just made the same mistake. All it takes to have this issue is two structs and an inline variable. Adding an empty constructor can be used as a workaround.
|
@llvm/issue-subscribers-clang-frontend |
I'm observing the same problem under Clang 15 whereas GCC 10.2 compiles the same code just fine. A sample (probably too verbose): #include <utility>
template <typename T, typename... DummyArgs>
class Parameter
{
public:
template <typename... Args>
explicit constexpr Parameter(Args&&... args):
parameter{std::forward<Args>(args)...}
{
}
template <typename... Args>
static constexpr decltype(auto) make(Args&&... args)
{
return Parameter<T, Args...>{std::forward<Args>(args)...};
}
private:
T parameter;
};
#define PARAMETER_OBJ(TYPE, NAME, ...) \
decltype(Parameter<TYPE>::make(__VA_ARGS__)) NAME{__VA_ARGS__}
struct Holder
{
struct A
{
PARAMETER_OBJ(int, value);
};
struct B
{
PARAMETER_OBJ(A, a);
};
}; see also https://godbolt.org/z/Pha8x8Td1 It seems a fix that works in my case was to move Another workaround is to skip the Parameter<int> value; and it is enough that at least one of Yet another solution seems to be skipping the template <typename... Args>
static constexpr Parameter<T, Args...> make(Args&&... args); then again, the problem goes away. |
Confirmed on post-17 trunk. |
@llvm/issue-subscribers-c-1 Author: None (JVApen)
| | |
| --- | --- |
| Bugzilla Link | [36684](https://llvm.org/bz36684) |
| Version | 6.0 |
| OS | Windows NT |
| Attachments | [Complete Reproduction](https://user-images.githubusercontent.com/95090374/143757229-760b5733-b840-4596-9cdd-60169cdc0be8.gz) |
| CC | @Ivan171,@JVApen,@zygoloid,@rnk,@steveire |
Extended DescriptionFollowing code compiles with MSVC 2015 and not with Clang-Cl: run.bat
t.cpp
error
|
Slightly reduced class Foo {
public:
struct Bar {
int num = 5;
};
Foo(Bar bar = Bar{})
: m_bar(bar) {}
Bar m_bar;
};
Foo foo; |
I've just encountered the same problem. Here is a more reduced example:
|
This looks like another version of cwg1890 et al which also is the issue in: #68527 I don't think anyone has looked into what it would take to fix this yet. |
Extended Description
Following code compiles with MSVC 2015 and not with Clang-Cl:
run.bat
t.cpp
error
The text was updated successfully, but these errors were encountered: