* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
@ 2023-04-27 7:03 ` pinskia at gcc dot gnu.org
2023-04-27 7:09 ` carlosgalvezp at gmail dot com
` (18 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-27 7:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
std::span, std::reference_wrapper and std::ref_view are all special cased for
the warning.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
2023-04-27 7:03 ` [Bug c++/109642] " pinskia at gcc dot gnu.org
@ 2023-04-27 7:09 ` carlosgalvezp at gmail dot com
2023-04-27 15:49 ` mpolacek at gcc dot gnu.org
` (17 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: carlosgalvezp at gmail dot com @ 2023-04-27 7:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
--- Comment #2 from Carlos Galvez <carlosgalvezp at gmail dot com> ---
Is there a way to tag classes to mark them for exclusion? Currently the warning
is part of -Wall and leads to many false positives. The warning message also
says "possibly" dangling reference. In my opinion "possibly" type of warnings
should not be part of -Wall due to the high FP rate.
I also find it strange that it complains about const references, which anyway
extend the lifetime of the temporary, or?
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
2023-04-27 7:03 ` [Bug c++/109642] " pinskia at gcc dot gnu.org
2023-04-27 7:09 ` carlosgalvezp at gmail dot com
@ 2023-04-27 15:49 ` mpolacek at gcc dot gnu.org
2023-04-27 19:20 ` carlosgalvezp at gmail dot com
` (16 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-04-27 15:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Sorry, you need to use
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-reference"
...
#pragma GCC diagnostic pop
when using MySpan here, because the compiler can't figure out it's
std::span-like.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (2 preceding siblings ...)
2023-04-27 15:49 ` mpolacek at gcc dot gnu.org
@ 2023-04-27 19:20 ` carlosgalvezp at gmail dot com
2023-04-28 13:00 ` mpolacek at gcc dot gnu.org
` (15 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: carlosgalvezp at gmail dot com @ 2023-04-27 19:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
--- Comment #4 from Carlos Galvez <carlosgalvezp at gmail dot com> ---
While I can do that on my own code, I cannot add that suppression on
third-party code, like Eigen (which I also get a lot of false positives in
similar code), even if I include the header via -isystem - since the warnings
are on the client side.
Is this really the expected behavior of a warning belonging to -Wall? Has this
warning been tested on large projects to evaluate the false positive rate?
Would you consider perhaps reducing the scope of the warning in order to reduce
the false positive rate, alternatively move it out of Wall?
It's sad that a lot of work and effort was put into creating this warning and
it will just probably be disabled on most projects. When a tool produces a lot
of false positives, there is high risk that developers stop trusting the tool
and true positives are ignored.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (3 preceding siblings ...)
2023-04-27 19:20 ` carlosgalvezp at gmail dot com
@ 2023-04-28 13:00 ` mpolacek at gcc dot gnu.org
2023-04-28 14:08 ` carlosgalvezp at gmail dot com
` (14 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-04-28 13:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Last reconfirmed| |2023-04-28
Status|UNCONFIRMED |ASSIGNED
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Carlos Galvez from comment #4)
> While I can do that on my own code, I cannot add that suppression on
> third-party code, like Eigen (which I also get a lot of false positives in
> similar code), even if I include the header via -isystem - since the
> warnings are on the client side.
>
> Is this really the expected behavior of a warning belonging to -Wall? Has
> this warning been tested on large projects to evaluate the false positive
> rate?
Yes, we've compiled a whole distro and the false positive rate was actually
surprisingly low, except now that GCC 13 was released it seems the
std::span-like false positives are actually a big deal. :( So...
> Would you consider perhaps reducing the scope of the warning in order to
> reduce the false positive rate, alternatively move it out of Wall?
...I think I'll have to move it to -Wextra (for GCC 13.2). Considering any
class with a T* member a std::span-like class would probably diminish the
warning too much. Maybe we need a [[gcc::whatever]] attribute to mark a class
as a reference-wrapper-like.
> It's sad that a lot of work and effort was put into creating this warning
> and it will just probably be disabled on most projects. When a tool produces
> a lot of false positives, there is high risk that developers stop trusting
> the tool and true positives are ignored.
Indeed. I'm sorry about the trouble you've had with the warning. I can
certainly understand why it's frustrating.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (4 preceding siblings ...)
2023-04-28 13:00 ` mpolacek at gcc dot gnu.org
@ 2023-04-28 14:08 ` carlosgalvezp at gmail dot com
2023-05-02 19:49 ` cvs-commit at gcc dot gnu.org
` (13 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: carlosgalvezp at gmail dot com @ 2023-04-28 14:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
--- Comment #6 from Carlos Galvez <carlosgalvezp at gmail dot com> ---
Sounds great, thanks for the quick response! I believe "-Wall -Wextra" is the
"bare minimum" set of warnings for most projects so I'm afraid people might
still need to disable it via "-Wno*".
Adding some [[gcc::whatever]] attribute sounds like a very interesting
approach, I believe Clang has a similar thing.
It's not really a blocker since we can just disable it, I'm just sad to have to
do it since I believe it's a really good warning to have!
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (5 preceding siblings ...)
2023-04-28 14:08 ` carlosgalvezp at gmail dot com
@ 2023-05-02 19:49 ` cvs-commit at gcc dot gnu.org
2023-06-21 18:43 ` pinskia at gcc dot gnu.org
` (12 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-02 19:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:6b927b1297e66e26e62e722bf15c921dcbbd25b9
commit r13-7276-g6b927b1297e66e26e62e722bf15c921dcbbd25b9
Author: Marek Polacek <polacek@redhat.com>
Date: Tue May 2 15:48:40 2023 -0400
c++: Move -Wdangling-reference to -Wextra [PR109642]
Sadly, -Wdangling-reference generates false positives for std::span-like
user classes, and it seems imprudent to attempt to improve the heuristic
in GCC 13. Let's move the warning to -Wextra, that will hopefully
reduce the number of false positives the users have been seeing with 13.
I'm leaving the warning in -Wall in 14 where I think I can write code
to detect std::span-like classes.
PR c++/109642
PR c++/109640
PR c++/109671
gcc/c-family/ChangeLog:
* c.opt (Wdangling-reference): Move from -Wall to -Wextra.
gcc/ChangeLog:
* doc/invoke.texi: Document that -Wdangling-reference is
enabled by -Wextra.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (6 preceding siblings ...)
2023-05-02 19:49 ` cvs-commit at gcc dot gnu.org
@ 2023-06-21 18:43 ` pinskia at gcc dot gnu.org
2023-06-21 18:51 ` mpolacek at gcc dot gnu.org
` (11 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-21 18:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |barry.revzin at gmail dot com
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 110358 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (7 preceding siblings ...)
2023-06-21 18:43 ` pinskia at gcc dot gnu.org
@ 2023-06-21 18:51 ` mpolacek at gcc dot gnu.org
2023-06-21 19:06 ` barry.revzin at gmail dot com
` (10 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-06-21 18:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
My plan is to allow users to do
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-reference"
...
#pragma GCC diagnostic pop
around the *class* itself to suppress the warning, not every use of the class.
Sorry, Carlos and Barry, that I haven't gotten around to it yet.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (8 preceding siblings ...)
2023-06-21 18:51 ` mpolacek at gcc dot gnu.org
@ 2023-06-21 19:06 ` barry.revzin at gmail dot com
2024-01-17 12:16 ` miro.palmu at helsinki dot fi
` (9 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: barry.revzin at gmail dot com @ 2023-06-21 19:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
--- Comment #10 from Barry Revzin <barry.revzin at gmail dot com> ---
Check out the report I opened for an example where the #pragma around the whole
class isn't really enough anyway - since you might want to disable the warning
for specializations of class/function templates.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (9 preceding siblings ...)
2023-06-21 19:06 ` barry.revzin at gmail dot com
@ 2024-01-17 12:16 ` miro.palmu at helsinki dot fi
2024-01-19 17:35 ` mpolacek at gcc dot gnu.org
` (8 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: miro.palmu at helsinki dot fi @ 2024-01-17 12:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
Miro Palmu <miro.palmu at helsinki dot fi> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |miro.palmu at helsinki dot fi
--- Comment #11 from Miro Palmu <miro.palmu at helsinki dot fi> ---
I'm not sure if this is useful information but, using span with a view in a
ranged-based for loop triggers false positive -Wdangling-referene on gcc 14.0.1
20240117 but not on gcc 13.2.
// On godbold: https://godbolt.org/z/x9jKh4MoW
#include <ranges>
#include <vector>
#include <span>
int main() {
const auto vec = std::vector{ 1, 2, 3 };
const auto s = std::span<decltype(vec)::value_type const>{vec};
// -Wwaring=dangling-reference on gcc 14.0.1 20240117 but not on gcc 13.2
for ([[maybe_unused]] auto _ : s | std::views::take(2)) { }
// No warning
for ([[maybe_unused]] auto _ : vec | std::views::take(2)) { }
// No warning
const auto s_view = s | std::views::take(2);
for ([[maybe_unused]] auto _ : s_view) { }
}
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (10 preceding siblings ...)
2024-01-17 12:16 ` miro.palmu at helsinki dot fi
@ 2024-01-19 17:35 ` mpolacek at gcc dot gnu.org
2024-01-19 23:32 ` mpolacek at gcc dot gnu.org
` (7 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-19 17:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |lopresti at gmail dot com
--- Comment #12 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
*** Bug 109671 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (11 preceding siblings ...)
2024-01-19 17:35 ` mpolacek at gcc dot gnu.org
@ 2024-01-19 23:32 ` mpolacek at gcc dot gnu.org
2024-01-22 20:52 ` mpolacek at gcc dot gnu.org
` (6 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-19 23:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
--- Comment #13 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
*** Bug 111159 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (12 preceding siblings ...)
2024-01-19 23:32 ` mpolacek at gcc dot gnu.org
@ 2024-01-22 20:52 ` mpolacek at gcc dot gnu.org
2024-01-22 21:16 ` cvs-commit at gcc dot gnu.org
` (5 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-22 20:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
--- Comment #14 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Miro Palmu from comment #11)
> I'm not sure if this is useful information but, using span with a view in a
> ranged-based for loop triggers false positive -Wdangling-referene on gcc
> 14.0.1 20240117 but not on gcc 13.2.
>
> // On godbold: https://godbolt.org/z/x9jKh4MoW
> #include <ranges>
> #include <vector>
> #include <span>
>
> int main() {
> const auto vec = std::vector{ 1, 2, 3 };
> const auto s = std::span<decltype(vec)::value_type const>{vec};
>
> // -Wwaring=dangling-reference on gcc 14.0.1 20240117 but not on gcc 13.2
> for ([[maybe_unused]] auto _ : s | std::views::take(2)) { }
>
> // No warning
> for ([[maybe_unused]] auto _ : vec | std::views::take(2)) { }
>
> // No warning
> const auto s_view = s | std::views::take(2);
> for ([[maybe_unused]] auto _ : s_view) { }
> }
This should be fixed now. I'm going to expand Wdangling-reference17.C with
this test though. Thanks.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (13 preceding siblings ...)
2024-01-22 20:52 ` mpolacek at gcc dot gnu.org
@ 2024-01-22 21:16 ` cvs-commit at gcc dot gnu.org
2024-01-30 18:32 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-22 21:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
--- Comment #15 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:c596ce03120cc22e141186401c6656009ddebdaa
commit r14-8339-gc596ce03120cc22e141186401c6656009ddebdaa
Author: Marek Polacek <polacek@redhat.com>
Date: Mon Jan 22 16:12:33 2024 -0500
c++: extend Wdangling-reference17.C [PR109642]
This patch extends g++.dg/warn/Wdangling-reference17.C with code
from PR109642. I'm not creating a new test because this one
already #includes the required headers.
PR c++/109642
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wdangling-reference17.C: Additional testing.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (14 preceding siblings ...)
2024-01-22 21:16 ` cvs-commit at gcc dot gnu.org
@ 2024-01-30 18:32 ` mpolacek at gcc dot gnu.org
2024-01-30 18:38 ` lopresti at gmail dot com
` (3 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-30 18:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #16 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Should be fixed with r14-8636.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (15 preceding siblings ...)
2024-01-30 18:32 ` mpolacek at gcc dot gnu.org
@ 2024-01-30 18:38 ` lopresti at gmail dot com
2024-01-30 18:42 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
19 siblings, 0 replies; 21+ messages in thread
From: lopresti at gmail dot com @ 2024-01-30 18:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
--- Comment #17 from Patrick J. LoPresti <lopresti at gmail dot com> ---
Are all of the "duplicate" bugs also fixed by this change?
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (16 preceding siblings ...)
2024-01-30 18:38 ` lopresti at gmail dot com
@ 2024-01-30 18:42 ` mpolacek at gcc dot gnu.org
2024-03-01 20:55 ` cvs-commit at gcc dot gnu.org
2024-05-01 17:18 ` pinskia at gcc dot gnu.org
19 siblings, 0 replies; 21+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-30 18:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
--- Comment #18 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Should be. Let me know if some are still not fixed.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (17 preceding siblings ...)
2024-01-30 18:42 ` mpolacek at gcc dot gnu.org
@ 2024-03-01 20:55 ` cvs-commit at gcc dot gnu.org
2024-05-01 17:18 ` pinskia at gcc dot gnu.org
19 siblings, 0 replies; 21+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-01 20:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
--- Comment #19 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:c7607c4cf18986025430ca8626abfe56bfe87106
commit r14-9263-gc7607c4cf18986025430ca8626abfe56bfe87106
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Jan 25 16:38:51 2024 -0500
c++: implement [[gnu::no_dangling]] [PR110358]
Since -Wdangling-reference has false positives that can't be
prevented, we should offer an easy way to suppress the warning.
Currently, that is only possible by using a #pragma, either around the
enclosing class or around the call site. But #pragma GCC diagnostic tend
to be onerous. A better solution would be to have an attribute.
To that end, this patch adds a new attribute, [[gnu::no_dangling]].
This attribute takes an optional bool argument to support cases like:
template <typename T>
struct [[gnu::no_dangling(std::is_reference_v<T>)]] S {
// ...
};
PR c++/110358
PR c++/109642
gcc/cp/ChangeLog:
* call.cc (no_dangling_p): New.
(reference_like_class_p): Use it.
(do_warn_dangling_reference): Use it. Don't warn when the function
or its enclosing class has attribute gnu::no_dangling.
* tree.cc (cxx_gnu_attributes): Add gnu::no_dangling.
(handle_no_dangling_attribute): New.
gcc/ChangeLog:
* doc/extend.texi: Document gnu::no_dangling.
* doc/invoke.texi: Mention that gnu::no_dangling disables
-Wdangling-reference.
gcc/testsuite/ChangeLog:
* g++.dg/ext/attr-no-dangling1.C: New test.
* g++.dg/ext/attr-no-dangling2.C: New test.
* g++.dg/ext/attr-no-dangling3.C: New test.
* g++.dg/ext/attr-no-dangling4.C: New test.
* g++.dg/ext/attr-no-dangling5.C: New test.
* g++.dg/ext/attr-no-dangling6.C: New test.
* g++.dg/ext/attr-no-dangling7.C: New test.
* g++.dg/ext/attr-no-dangling8.C: New test.
* g++.dg/ext/attr-no-dangling9.C: New test.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/109642] False Positive -Wdangling-reference with std::span-like classes
2023-04-27 6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
` (18 preceding siblings ...)
2024-03-01 20:55 ` cvs-commit at gcc dot gnu.org
@ 2024-05-01 17:18 ` pinskia at gcc dot gnu.org
19 siblings, 0 replies; 21+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-01 17:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |oleg at smolsky dot net
--- Comment #20 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 114909 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 21+ messages in thread