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

            Bug ID: 49263
           Summary: clang: accept-invalid ill-formed C program / assertion
                    `getLangOpts().CPlusPlus && "Call sites of this
                    function should be guarded by checking for C++"'
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: zhan3...@purdue.edu
                CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org,
                    neeil...@live.com, richard-l...@metafoo.co.uk

Clang accepts this presumably-invalid code, which GCC rejects. It affects 11.0,
12.0, and trunk.

clang: https://godbolt.org/z/b7oaxq  
GCC: https://godbolt.org/z/1194qP

---

$ cat test.c
struct another_struct {
    int my_int;
};

struct my_struct {
    struct {
        int volatile (*func_ptr)(int[] = <, struct another_struct);
    };
};

int volatile func(int a[]) { return a[0]; }

int main() {
    struct my_struct x = { .func_ptr = &func };
    int y = 1;

    return (*x.func_ptr)(&y);
}

$ ./clang -o /tmp/a.out -x c -std=c11 -pedantic -Wall test.c
# no any warning or error

---

I try to make the compilation as strict as possible, so I set "-std=c11
-pedantic -Wall". Actually, the standard does not matter.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to