[cfe-dev] clang++ vs. ClangTool.buildASTs()

Frank Redeker via cfe-dev cfe-dev at lists.llvm.org
Thu Nov 30 05:33:48 PST 2017

Hello all,

When compiling the following code there is a difference when using
clang++ from command line or ClangTool.buildASTs().

unsigned long *	Pointer = (int) 0;

clang++ -c foo.cpp:
warning: expression which evaluates to zero treated as a null pointer
constant of type 'unsigned long *' [-Wnon-literal-null-conversion]

error: cannot initialize a variable of type 'unsigned long *' with an
rvalue of type 'int'

The code to build the AST is similar to this.

OptionCategory category("MYTOOL");
const char *   argv[32];
int            argc=0;

argv[argc++] = "MYTOOL";
argv[argc++] = "file.c";
argv[argc++] = "-x";
argv[argc++] = "c++";
argv[argc++] = "--";

CommonOptionsParser cop(argc, (const char **) argv, category);
ClangTool           tool(cop.getCompilations(), cop.getSourcePathList());

vector<unique_ptr<ASTUnit>>		asts;

int result = tool.buildASTs(asts);

Is there something I'm missing to pass to the ClangTool to avoid that an
error is emitted instead of a warning.


More information about the cfe-dev mailing list