public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104798] New: Regression: [[gnu::always_inline]] ignored on lambda, no warning emitted
@ 2022-03-05 16:30 jstein27 at binghamton dot edu
  2022-03-05 16:38 ` [Bug c++/104798] " jstein27 at binghamton dot edu
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jstein27 at binghamton dot edu @ 2022-03-05 16:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104798

            Bug ID: 104798
           Summary: Regression: [[gnu::always_inline]] ignored on lambda,
                    no warning emitted
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jstein27 at binghamton dot edu
  Target Milestone: ---

GCC 8: always_inline works on lambdas with both the __attribute__ syntax and
the attribute specifier sequence syntax.

GCC 9: always_inline works on lambdas with the __attribute__ syntax but not the
attribute specifier sequence syntax, a warning is emitted with -Wattributes.

GCC 10, 11: always_inline works on lambdas with the __attribute__ syntax but
not the attribute specifier sequence syntax, a warning is NOT emitted with
-Wattributes.

Originally noticed on Compiler Explorer, so unfortunately, I can't provide more
details easily regarding how the compiler was compiled and so on.

Compiler explorer link to play with: https://gcc.godbolt.org/z/cnqh3v5of

Code snippet:

#include <cstdio>

#if USE_SCOPED
static auto l1 = [](auto v) [[gnu::always_inline]]
{
    printf("%d\n", v * 2);
};
#else
static auto l1 = [](auto v) __attribute__((always_inline))
{
    printf("%d\n", v * 2);
};
#endif

int main() {
    l1(1);
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/104798] Regression: [[gnu::always_inline]] ignored on lambda, no warning emitted
  2022-03-05 16:30 [Bug c++/104798] New: Regression: [[gnu::always_inline]] ignored on lambda, no warning emitted jstein27 at binghamton dot edu
@ 2022-03-05 16:38 ` jstein27 at binghamton dot edu
  2022-03-06  2:18 ` jstein27 at binghamton dot edu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: jstein27 at binghamton dot edu @ 2022-03-05 16:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104798

--- Comment #1 from Jonathan Stein <jstein27 at binghamton dot edu> ---
Possibly related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90333

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/104798] Regression: [[gnu::always_inline]] ignored on lambda, no warning emitted
  2022-03-05 16:30 [Bug c++/104798] New: Regression: [[gnu::always_inline]] ignored on lambda, no warning emitted jstein27 at binghamton dot edu
  2022-03-05 16:38 ` [Bug c++/104798] " jstein27 at binghamton dot edu
@ 2022-03-06  2:18 ` jstein27 at binghamton dot edu
  2022-03-06  4:05 ` jstein27 at binghamton dot edu
  2022-03-07 13:12 ` marxin at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jstein27 at binghamton dot edu @ 2022-03-06  2:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104798

--- Comment #2 from Jonathan Stein <jstein27 at binghamton dot edu> ---
Further, after some back and forth with a colleague, I don't know if this is an
extension or not. I'm not too clear on the language, but from the C++20
published draft n4849:

> An attribute-specifier-seq in a lambda-declarator appertains to the **type of** the corresponding
function call operator or **operator template**.

Emphasis mine. A decl-specifier-seq is also allowed, which can have it's own
attribute-specifier-seq which apertains to the type of item that the
decl-specifiers were for. But the decl specifiers for a lambda expression are
only allowed to contain mutable, constexpr, or consteval. The latter two would
be for the operator, but I believe mutable would be for anonymous class.

Is the type of a function call operator the same as the operator? I assume so,
because as far as I'm aware templates ( don't have a type. Which would then
mean, if there's "decl-specifier-seq [[...]] noexcept-spec [[...]]"
(noexcept-spec is optional), the first attribute-specifier-seq _may_ pertain to
the anonymous class (because what does it mean *exactly* to be mutable here
other than for the class), the second to the call operator. If there's only an
attribute-specifier-seq, it's to the call operator. Which means both the lack
of warning and the change in behavior are wrong.

On the other hand, if not, then it applies to the type of the function yet not
the function itself. Which means there's no way to provide function-related
attributes to lambdas pre C++2b except by extension, and the change in behavior
is correct but the lack of warning is not.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/104798] Regression: [[gnu::always_inline]] ignored on lambda, no warning emitted
  2022-03-05 16:30 [Bug c++/104798] New: Regression: [[gnu::always_inline]] ignored on lambda, no warning emitted jstein27 at binghamton dot edu
  2022-03-05 16:38 ` [Bug c++/104798] " jstein27 at binghamton dot edu
  2022-03-06  2:18 ` jstein27 at binghamton dot edu
@ 2022-03-06  4:05 ` jstein27 at binghamton dot edu
  2022-03-07 13:12 ` marxin at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jstein27 at binghamton dot edu @ 2022-03-06  4:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104798

--- Comment #3 from Jonathan Stein <jstein27 at binghamton dot edu> ---
Last update on this for today from me: If there is a difference between "type
of" the operator and the operator itself language wise, then there's a
different but related regression that appears to break standards conformity:
the type now does not get attributes (such as deprecated) applied to it,
whereas it previously did (and so did use of the lambda, but now it correctly
does not).

Compiler explorer and codesnippet: https://gcc.godbolt.org/z/8WGvPsaGh

#include <cstdio>
#include <type_traits>

static auto l1 = [](int v) [[deprecated]]
{
    printf("%d\n", v * 2);
};
using t1 [[deprecated]] = long;

int main() {
    decltype(&std::decay_t<decltype(l1)>::operator()) test;
    decltype(t1{}) test2;
    l1(1); // test 3 
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/104798] Regression: [[gnu::always_inline]] ignored on lambda, no warning emitted
  2022-03-05 16:30 [Bug c++/104798] New: Regression: [[gnu::always_inline]] ignored on lambda, no warning emitted jstein27 at binghamton dot edu
                   ` (2 preceding siblings ...)
  2022-03-06  4:05 ` jstein27 at binghamton dot edu
@ 2022-03-07 13:12 ` marxin at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-03-07 13:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104798

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=93530
   Last reconfirmed|                            |2022-03-07
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #4 from Martin Liška <marxin at gcc dot gnu.org> ---
The warning is gone since r10-6397-gb817be038d94c987.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-03-07 13:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-05 16:30 [Bug c++/104798] New: Regression: [[gnu::always_inline]] ignored on lambda, no warning emitted jstein27 at binghamton dot edu
2022-03-05 16:38 ` [Bug c++/104798] " jstein27 at binghamton dot edu
2022-03-06  2:18 ` jstein27 at binghamton dot edu
2022-03-06  4:05 ` jstein27 at binghamton dot edu
2022-03-07 13:12 ` marxin at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).