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

            Bug ID: 114305
           Summary: GCC doesn't use [[gnu::pure]] attribute on the inline
                    function
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: khim at google dot com
  Target Milestone: ---

The following program is an illustration (https://godbolt.org/z/PYW34ccvP):

#include <cstddef>

GNU_PURE1 extern size_t foo(size_t);

template <size_t size>
GNU_PURE2 inline size_t test() {
    return foo(size);
}

int test_func(int x, int y) {
    return test<sizeof x>() + test<sizeof y>();
}

If GNU_PURE1 is [[gnu::pure]] then both gcc and clang optimize away second
call, if GNU_PURE2 is [[gnu::pure]] then only clang does that.

That means that it's impossible to add [[gnu::pure]] optimization on top of
function that's pure according to the docs but is not declared as such in the
header file.

Reply via email to