Skip to content

Incorrect semantic error reported by clang++ when using "uint16_t" together with global namespace. #121457

Open
@lichenxuan87

Description

Source code and error message

Error message was reported by clang++ when compiling below source code:

#include <stdint.h>

class CLangTester {
 public:
    uint8_t test();
};

uint8_t ::CLangTester::test() {
    return 23;
}

int main() {
    CLangTester tester;
    tester.test();
    return 0;
}

Error message:

/usr/bin/clang++ -c -I/usr/local/include -I. -Wall -g -std=c++14 namespace.cpp -o build/namespace.o
namespace.cpp:21:1: error: 'uint8_t' (aka 'unsigned char') is not a class, namespace, or enumeration
uint8_t ::CLangTester::test() {
^
1 error generated.
make: *** [Makefile:28: build/namespace.o] Error 1

Passed when using g++

g++ -c -I/usr/local/include -I. -Wall -g -std=c++14 namespace.cpp -o build/namespace.o
g++ build/namespace.o -L/usr/local/lib -L/usr/lib -lrt -pthread -Wl,-rpath-link,/usr/lib,-rpath-link,/usr/local/lib  -o clang-namespace 

Version info

clang --version output:

clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Additional info

The error disappears when I changed

uint8_t ::CLangTester::test() {

to

uint8_t CLangTester::test() {

Apparently the clang++ ignored the space between uint8_t and ::, while ::ClangTester is totally valid.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions