Bug 206335 - clang++ -x c++ issue : expected unqualified-id
Summary: clang++ -x c++ issue : expected unqualified-id
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.2-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs mailing list
URL: http://www-crypto.htw-saarland.de/web...
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-17 14:37 UTC by DW
Modified: 2016-02-21 15:19 UTC (History)
1 user (show)

See Also:


Attachments
tar file containing sources showing the bug via "make" (5.50 KB, application/x-tar)
2016-01-17 14:43 UTC, DW
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description DW 2016-01-17 14:37:52 UTC

    
Comment 1 DW 2016-01-17 14:43:39 UTC
Created attachment 165715 [details]
tar file containing sources showing the bug via "make"

tar file

clang_x_cpp_bug/
clang_x_cpp_bug/test-x_cpp.c
clang_x_cpp_bug/test-function.h
clang_x_cpp_bug/test-function.c
clang_x_cpp_bug/Makefile
Comment 2 DW 2016-01-17 14:45:33 UTC
Abstract
Seems I have found a clang++ bug if called with -x c++.

    system is FreeBSD 10.2-STABLE (TESTBOX) #0 r290820M
    compiler is clang 3.4.1, in particular

      $ clang++ -v
      FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
      Target: x86_64-unknown-freebsd10.2
      Thread model: posix
      Selected GCC installation: 
      

    compiler clang 3.6 from ports also affected
    compiler clang 3.7 to be checked 

To reproduce

    download clang_x_cpp_bug.tar
    tar xf clang_x_cpp_bug.tar
    cd clang_x_cpp_bug
    make
Comment 3 Hubert Drogosz 2016-02-21 13:08:29 UTC
It seems to me that it isn't a bug. For me clang does what it should do. 
Taking from clang man page:

-x <language>

    Treat subsequent input files as having type language.

So for me it means that it should treat every file after -x option as file of this type.
As you're passing object file (test-function.o) after -x c++ option, it tries to interpret this file like c++ source file, and it fails. 
I think you should compile it this way:

    clang++ -o test-x_cpp test-function.o -x c++ test-x_cpp.c

Unfortunately, there isn't an option to pass object file after using -x option, so object files should be passed before using any -x option.
Comment 4 DW 2016-02-21 15:19:38 UTC
(In reply to Hubert Drogosz from comment #3)

Yes, makes sense. Thank you.

The error message is misleading at first, though, but (with hindsight) makes sense, too.

:: test-function.o:1:1: error: expected unqualified-id
:: ELF 
:: ^
:: test-function.o:1:9: warning: null character ignored [-Wnull-character]
:: ELF 

Far more obvious would be an error message like this:

:: test-function.o: not a C++ source file, aborting