libclang unexpected diagnostic

hi guys, i write a programme using libclang , as follows

//clang_test.cpp
int main( int argc, char** argv )
{
CXIndex Index = clang_createIndex( 0, 0 );
CXTranslationUnit TU = clang_parseTranslationUnit( Index, 0, argv, argc, 0, 0, CXTranslationUnit_None );

if(TU == NULL)
return -1;

for( unsigned I=0, N=clang_getNumDiagnostics( TU ); I<N; ++I )
{
CXDiagnostic Diag = clang_getDiagnostic( TU, I );
/
/
CXString String = clang_formatDiagnostic( Diag, clang_defaultDiagnosticDisplayOptions() );
fprintf( stderr, “Diag: %s\n”, clang_getCString( String ) );
clang_disposeString( String );

/
/
for( unsigned J=0, M=clang_getDiagnosticNumFixIts( Diag ); J!=M; ++J )
{
CXSourceRange Range;
CXString Str2 = clang_getDiagnosticFixIt( Diag, J, &Range );
const char* str = clang_getCString( Str2 );
if( str!= 0 )
{
fprintf( stderr, “FixIt: %s\n”, str );
CXSourceLocation Start = clang_getRangeStart( Range );
CXSourceLocation End = clang_getRangeEnd( Range );
unsigned line = 0;
unsigned column = 0;
clang_getSpellingLocation( Start, 0, &line, &column, 0 );
fprintf( stderr, “Range start: line [%d], column [%d]\n”, line, column );
clang_getSpellingLocation( End, 0, &line, &column, 0 );
fprintf( stderr, “Range end: line [%d], column [%d]\n”, line, column );
}

clang_disposeString( Str2 );
}
clang_disposeDiagnostic(Diag);
}

clang_disposeTranslationUnit( TU );
clang_disposeIndex( Index );
return 0;
}
//test.cpp
#include <stdio.h>

int PrintExtent( )
{
}

when run ./clang_test test.cpp, it prints
Diag: warning: ./clang_test: ‘linker’ input unused when ‘-fsyntax-only’ is present
Diag: test.cpp:5:1: warning: control reaches end of non-void function [-Wreturn-type]

My question is why does it print the first message, and how can i forbid it to print this message.

Thanks.
|

The first warning comes from the driver when processing the command line arguments. You are essentially passing a flag to the compiler that would only be used when doing a link, but you are doing -fsyntax-only.

Internally you can suppress the warning by remapping the diagnostic to “ignore”, but there is no API for that in the high-level libclang API (unless the warning has a matching -WFOO command line flag, which allows you to pass -Wno-FOO to suppress the warning).