| Summary: | [C++0x] Generalized constant expressions | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Tools] CDT | Reporter: | Markus Schorn <mschorn.eclipse> | ||||
| Component: | cdt-parser | Assignee: | Nathan Ridge <zeratul976> | ||||
| Status: | RESOLVED FIXED | QA Contact: | Markus Schorn <mschorn.eclipse> | ||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | cdtdoug, eclipse.sprigogin, gpiez, olexiyb, vagran.ast, woskimi, yevshif, zeratul976 | ||||
| Version: | 8.0 | ||||||
| Target Milestone: | 8.4.0 | ||||||
| Hardware: | PC | ||||||
| OS: | All | ||||||
| Whiteboard: | |||||||
| Bug Depends on: | |||||||
| Bug Blocks: | 327297 | ||||||
| Attachments: |
|
||||||
|
Description
Markus Schorn
*** Bug 361043 has been marked as a duplicate of this bug. *** I Have been hit by this now, this leads to not resolving std::chrono::duration_cast in gcc-4.6.2. Would it be possible to add it as an storage specifier like "__thread" or "thread_local"? The constness of the actual expression doesn't need to be proved by CDT IMHO. (In reply to comment #2) > I Have been hit by this now, this leads to not resolving > std::chrono::duration_cast in gcc-4.6.2. Would it be possible to add it as an > storage specifier like "__thread" or "thread_local"? The constness of the > actual expression doesn't need to be proved by CDT IMHO. There are actually two parts for supporting this new feature: * We need to handle the syntax, which should not be a big issue. * For the purpose of template instantiation, CDT will have to be able to evaluate the new kind of constant expressions. This involves storing expressions in the index. Therefore there is some relationship to bug 299911. Parsing support for constexpr keyword has been added in commit http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=e55325538485fe691418c4b50c7a4d947239d95c. Evaluation of constexpr functions was added recently. The only remaining part is constant expressions of aggregate types. *** cdt git genie on behalf of Sergey Prigogin ***
Bug 332829. Parsing support for constexpr keyword. Also added few
new C++11 keywords.
[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=e55325538485fe691418c4b50c7a4d947239d95c
Created attachment 233149 [details]
a test case that causes trouble
see inside the code for details
could this also be related to bug 402617 ? (In reply to comment #8) > could this also be related to bug 402617 ? I meant the problem in the attached file, of course. (In reply to comment #7) > Created attachment 233149 [details] > a test case that causes trouble > > see inside the code for details Reduced: constexpr int f() { return 1; } template <int> struct A { static void g() {} }; void bar() { A<f()>::g(); // ERROR HERE: "Function 'g' could not be resolved" } (In reply to comment #10) > (In reply to comment #7) > > Created attachment 233149 [details] > > a test case that causes trouble > > > > see inside the code for details > > Reduced: > > > constexpr int f() { return 1; } > > template <int> > struct A > { > static void g() {} > }; > > void bar() > { > A<f()>::g(); // ERROR HERE: "Function 'g' could not be resolved" > } Seems to be a parsing problem. The "f()" in "A<f()>" is being parsed as a type-id rather than an expression. (In reply to comment #11) > (In reply to comment #10) > > (In reply to comment #7) > > > Created attachment 233149 [details] > > > a test case that causes trouble > > > > > > see inside the code for details > > > > Reduced: > > > > > > constexpr int f() { return 1; } > > > > template <int> > > struct A > > { > > static void g() {} > > }; > > > > void bar() > > { > > A<f()>::g(); // ERROR HERE: "Function 'g' could not be resolved" > > } > > Seems to be a parsing problem. The "f()" in "A<f()>" is being parsed as a > type-id rather than an expression. It looks like GNUCPPSourceParser.templateArgument() doesn't handle the case where a template argument could syntactically be either a type-id or a function-call-expression - it just constructs a type-id in such cases. This was probably correct in C++98, when a function-call-expression couldn't be a constant expression and thus couldn't appear in a template argument. In C++11, though, it's wrong - it should construct an ambiguous template argument, just like it does for a type-id/id-expression ambiguity. I don't have a good enough understanding of the parser to fix this myself, I just wanted to document my investigation. does this fall into the same category or is this a different bug?
enum class TestEnum : int {
E1, E2
}
template<int P>
struct A {
};
A<TestEnum::E1> a1;
(In reply to Michael Woski from comment #13) It probably makes sense to deal with these cases one by one. Michael, could you please create a separate bug for your test case. (In reply to comment #14) ok, it's in bug #419175 (In reply to Nathan Ridge from comment #12) > (In reply to comment #11) > > (In reply to comment #10) > > > (In reply to comment #7) > > > > Created attachment 233149 [details] > > > > a test case that causes trouble > > > > > > > > see inside the code for details > > > > > > Reduced: > > > > > > > > > constexpr int f() { return 1; } > > > > > > template <int> > > > struct A > > > { > > > static void g() {} > > > }; > > > > > > void bar() > > > { > > > A<f()>::g(); // ERROR HERE: "Function 'g' could not be resolved" > > > } > > > > Seems to be a parsing problem. The "f()" in "A<f()>" is being parsed as a > > type-id rather than an expression. > > It looks like GNUCPPSourceParser.templateArgument() doesn't handle the case > where a template argument could syntactically be either a type-id or a > function-call-expression - it just constructs a type-id in such cases. This > was probably correct in C++98, when a function-call-expression couldn't be a > constant expression and thus couldn't appear in a template argument. In > C++11, though, it's wrong - it should construct an ambiguous template > argument, just like it does for a type-id/id-expression ambiguity. > > I don't have a good enough understanding of the parser to fix this myself, I > just wanted to document my investigation. Decided to give this a shot: https://git.eclipse.org/r/#/c/20140/ Fixed by the Nathan's change. (In reply to Sergey Prigogin from comment #17) > Fixed by the Nathan's change. What my patch fixed was Michael's test case in comment #7. Is the bug as a whole fixed? In particular, is the part mentioned in comment 5 ("constant expressions of aggregate types") implemented? (In reply to Sergey Prigogin from comment #5) > Evaluation of constexpr functions was added recently. The only remaining > part is constant expressions of aggregate types. (In reply to Nathan Ridge from comment #18) > Is the bug as a whole fixed? In particular, is the part mentioned in comment > 5 ("constant expressions of aggregate types") implemented? I don't know exactly what "constant expression of aggregate types" really means, but does this also cover std::enable_if templates and the likes. I'm asking because things like class A : std::enable_if<condition,B>::type{}; do not work. (In reply to Michael Woski from comment #19) > (In reply to Nathan Ridge from comment #18) > > > Is the bug as a whole fixed? In particular, is the part mentioned in comment > > 5 ("constant expressions of aggregate types") implemented? > > I don't know exactly what "constant expression of aggregate types" really > means, but does this also cover std::enable_if templates and the likes. I'm > asking because things like > > class A : std::enable_if<condition,B>::type{}; > > do not work. please forget that, I messed things up. std::enable_if expressions work fine as a template parameter (In reply to Nathan Ridge from comment #18) > What my patch fixed was Michael's test case in comment #7. I don't know which patch fixed the test case in comment #7, but it appears to work now. > > Is the bug as a whole fixed? In particular, is the part mentioned in comment > 5 ("constant expressions of aggregate types") implemented? Constant expressions of aggregate types are not implemented. I've created bug 442612 to track it separately. |