Repository navigation
Fix #15087 FP constParameterReference (returning reference to member in ternary) #8918
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
base: main
Are you sure you want to change the base?
Changes from all commits
8387608
9de5bdd
a32896b
6c6c205
9716105
74b89d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4225,6 +4225,17 @@ class TestOther : public TestFixture { | |
| " int select(DS &ds) { return select(ds, [](int) {}); }\n" | ||
| "};\n"); | ||
| ASSERT_EQUALS("", errout_str()); | ||
|
|
||
| check("struct S {\n" // #15087 | ||
| " int a, b;\n" | ||
| "};\n" | ||
| "int& f(S& s, bool b) {\n" | ||
| " return b ? s.a : s.b;\n" | ||
| "}\n" | ||
| "int* g(U& u) {\n" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI review
|
||
| " return &(u.i);\n" | ||
| "}\n"); | ||
| ASSERT_EQUALS("", errout_str()); | ||
| } | ||
|
|
||
| void constParameterCallback() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI review
This only follows the member side of
., so a ternary in the object expression is not reached.int& g(S& s, S& t, bool b) { return (b ? s : t).a; }still givesconstParameterReferencefor bothsandt, and both are wrong because the function returns a non-constint&. Visitingop1of.as well (or both operands) would cover this case too.