[LLVMbugs] [Bug 6946] New: Clang should suggest a header to include for more standard names

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Apr 26 17:10:04 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=6946

           Summary: Clang should suggest a header to include for more
                    standard names
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Keywords: quality-of-implementation
          Severity: enhancement
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: jyasskin at google.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


Right now, clang suggests to include <stdio.h> when printf is used but not
defined in C, but not in C++. Clang also fails to suggest <stddef.h> for size_t
and ptrdiff_t in either language.

Clang should probably have a table of all the names commonly used from C, C++,
Posix, and Win32, and suggest appropriate headers for them when they're missing
a declaration. This is all relatively low priority.


$ cat test.cc
void foo() {
    size_t s;
    ptrdiff_t p;
    printf("Hello World\n");
}

$ clang -x c -c test.cc
test.cc:2:5: error: use of undeclared identifier 'size_t'; did you mean
'sizeof'?
    size_t s;
    ^
test.cc:3:5: error: use of undeclared identifier 'ptrdiff_t'
    ptrdiff_t p;
    ^
test.cc:4:5: warning: implicitly declaring C library function 'printf' with
type 'int (char const *, ...)'
    printf("Hello World\n");
    ^
test.cc:4:5: note: please include the header <stdio.h> or explicitly provide a
declaration for 'printf'
1 warning and 2 errors generated.

$ clang -x c++ -c test.cc
test.cc:2:5: error: use of undeclared identifier 'size_t'; did you mean
'sizeof'?
    size_t s;
    ^
test.cc:3:5: error: use of undeclared identifier 'ptrdiff_t'
    ptrdiff_t p;
    ^
test.cc:4:5: error: use of undeclared identifier 'printf'
    printf("Hello World\n");
    ^
3 errors generated.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list