[llvm-bugs] [Bug 30364] New: wrong __PRETTY_FUNCTION__ found, from the wrong scope

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 13 00:09:30 PDT 2016


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

            Bug ID: 30364
           Summary: wrong __PRETTY_FUNCTION__ found, from the wrong scope
           Product: clang
           Version: 3.9
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: marmoo1024 at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

For the following code produces a warning, and s is initialized from outside
the function.

#include <stdio.h>
void function() {
    struct obj {
       const char * str;
       obj(const char * s = __PRETTY_FUNCTION__ /*or __func__*/)
        : str(s) {};
    };
    printf ("%s\n",obj().str);
}
int main () {function();}

__func__ and __PRETTY_FUNCTION__ are supposed to be static const char *,
so they should be visible. Instead in 3.9 "top level" is printed. 

If __PRETTY_FUNCTION__ is replaced with a static variable, an error is produced
instead. 

#include <stdio.h>
const char other[] = "other";

void function() {
    static const char other[] = "other";
    struct obj {
        const char * str;
        obj(const char * s=other)
        : str(s){};
    };
    printf ("%s\n",obj().str);
}

int main () {function();}

-- 
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/20160913/35b81ca3/attachment.html>


More information about the llvm-bugs mailing list