[llvm-bugs] [Bug 47663] New: adding 'weak' on a redeclaration after the first use is unsound

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Sep 27 17:34:04 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47663

            Bug ID: 47663
           Summary: adding 'weak' on a redeclaration after the first use
                    is unsound
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Consider:

void f();
bool b = f;
void f() __attribute__((weak));

Clang emits 'b' constant-initialized to 'true', because that is the result of
evaluating the initializer at the point where it appears. (The language
semantics require us to evaluate the initializer at that point, and require
that initializer to be a constant expression that evaluates to 'true'.)

GCC handles this by rejecting the redeclaration:

<source>:1:6: error: 'void f()' declared weak after being used
    1 | void f();
      |      ^

However, GCC does accept this:

void f();
void g() { f(); }
void f() __attribute__((weak));

... so it's not entirely clear what rule they're using.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200928/5efdb36a/attachment.html>


More information about the llvm-bugs mailing list