Bug 729308

Summary: clang can't compile basic C++ programs
Product: [Fedora] Fedora Reporter: Tamás Szelei <szelei.t>
Component: llvmAssignee: Michel Lind <michel>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: 16CC: bos, dmalcolm, dtardon, jakub, jerome.benoit, jistone, joew60, mariuszs, michel, stiell
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: llvm-2.9-10.fc16 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-04-13 21:35:32 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Tamás Szelei 2011-08-09 13:23:07 UTC
Description of problem:
Consider the following C++ code:

[code]
#include <iostream>

int main(int argc, char* argv[])
{
    std::cout << "Hello World!\n"; 
}
[/code]

This fails to compile.

Version-Release number of selected component (if applicable):

$ yum info clang
Name        : clang
Arch        : x86_64
Version     : 2.8
Release     : 11.fc15
Size        : 16 M
Repo        : installed
From repo   : fedora
Summary     : A C language family front-end for LLVM
URL         : http://llvm.org/
License     : NCSA
Description : clang: noun
            :     1. A loud, resonant, metallic sound.
            :     2. The strident call of a crane or goose.
            :     3. C-language family front-end toolkit.
            : 
            : The goal of the Clang project is to create a new C, C++, Objective C
            : and Objective C++ front-end for the LLVM compiler. Its tools are built
            : as libraries and designed to be loosely-coupled and extensible.


How reproducible:
Always.

Steps to Reproduce:
1. yum groupinstall "Development Tools"
2. yum install clang
3. Create main.cpp with the above content.
4. Try to compile this file with "clang main.cpp"
  
Actual results:
The compilation fails with the following error messages:

In file included from main.cpp:1:
In file included from /usr/include/c++/4.6.0/iostream:39:
In file included from /usr/include/c++/4.6.0/ostream:39:
In file included from /usr/include/c++/4.6.0/ios:40:
In file included from /usr/include/c++/4.6.0/bits/char_traits.h:40:
/usr/include/c++/4.6.0/bits/stl_algobase.h:378:43: error: unexpected type name '_ValueTypeI': expected expression
      const bool __simple = (__is_trivial(_ValueTypeI)
                                          ^
/usr/include/c++/4.6.0/bits/stl_algobase.h:383:40: error: non-type template argument of type 'bool const' is not an integral constant expression
      return std::__copy_move<_IsMove, __simple,
                                       ^~~~~~~~
/usr/include/c++/4.6.0/bits/stl_algobase.h:573:43: error: unexpected type name '_ValueType1': expected expression
      const bool __simple = (__is_trivial(_ValueType1)
                                          ^
/usr/include/c++/4.6.0/bits/stl_algobase.h:578:49: error: non-type template argument of type 'bool const' is not an integral constant expression
      return std::__copy_move_backward<_IsMove, __simple,
                                                ^~~~~~~~
/usr/include/c++/4.6.0/bits/stl_algobase.h:731:32: error: expected ';' in 'for' statement specifier
      for (__decltype(__n + 0) __niter = __n;
                               ^
/usr/include/c++/4.6.0/bits/stl_algobase.h:732:5: error: use of undeclared identifier '__niter'
           __niter > 0; --__niter, ++__first)
           ^
/usr/include/c++/4.6.0/bits/stl_algobase.h:732:20: error: use of undeclared identifier '__niter'
           __niter > 0; --__niter, ++__first)
                          ^
/usr/include/c++/4.6.0/bits/stl_algobase.h:732:27: error: expected ')'
           __niter > 0; --__niter, ++__first)
                                 ^
/usr/include/c++/4.6.0/bits/stl_algobase.h:731:11: note: to match this '('
      for (__decltype(__n + 0) __niter = __n;
          ^
/usr/include/c++/4.6.0/bits/stl_algobase.h:743:32: error: expected ';' in 'for' statement specifier
      for (__decltype(__n + 0) __niter = __n;
                               ^
/usr/include/c++/4.6.0/bits/stl_algobase.h:744:5: error: use of undeclared identifier '__niter'
           __niter > 0; --__niter, ++__first)
           ^
/usr/include/c++/4.6.0/bits/stl_algobase.h:744:20: error: use of undeclared identifier '__niter'
           __niter > 0; --__niter, ++__first)
                          ^
/usr/include/c++/4.6.0/bits/stl_algobase.h:744:27: error: expected ')'
           __niter > 0; --__niter, ++__first)
                                 ^
/usr/include/c++/4.6.0/bits/stl_algobase.h:743:11: note: to match this '('
      for (__decltype(__n + 0) __niter = __n;
          ^
12 errors generated.

Expected results:
The compilation should be successful, it should not generate error messages and output a binary that prints "Hello World!" to stdout.

Additional info:
As a former Ubuntu user, I faced this very same issue before. If I understood correctly, the root cause of the problem is that GCC 4.6 ships with a standard library implementation that uses many C++0x features that clang 2.8 does not understand. In Ubuntu, there is a libstdc++4.5 package. Having that installed on that system, I was able to use clang before.

Comment 1 Jakub Jelinek 2011-08-24 07:45:03 UTC
I guess http://llvm.org/bugs/show_bug.cgi?id=9472 needs to be backported.
This bug exist also in llvm 2.9 in f16.

Comment 2 Fedora Update System 2012-03-11 16:15:45 UTC
llvm-2.8-15.fc15 has been submitted as an update for Fedora 15.
https://admin.fedoraproject.org/updates/llvm-2.8-15.fc15

Comment 3 Fedora Update System 2012-03-11 16:16:06 UTC
llvm-2.9-8.fc16 has been submitted as an update for Fedora 16.
https://admin.fedoraproject.org/updates/llvm-2.9-8.fc16

Comment 4 David Tardon 2012-03-13 09:04:07 UTC
I am getting the following error with the updated package:

clang++ -c -v test.cc
clang version 2.9 (tags/RELEASE_29/final)
Target: x86_64-redhat-linux-gnu
Thread model: posix
 "/usr/bin/clang" -cc1 -triple x86_64-redhat-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test.cc -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-linker-version 2.21.53.0.1 -momit-leaf-frame-pointer -v -resource-dir /usr/bin/../lib/clang/2.9 -ferror-limit 19 -fmessage-length 80 -fcxx-exceptions -fexceptions -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -o test.o -x c++ test.cc
clang -cc1 version 2.9 based upon llvm 2.9 hosted on x86_64-redhat-linux-gnu
ignoring nonexistent directory "/usr/include/c++/4.6.2"
ignoring nonexistent directory "/usr/include/c++/4.6.2/x86_64-redhat-linux/"
ignoring nonexistent directory "/usr/include/c++/4.6.2/backward"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.6.2/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/bin/../lib/clang/2.9/include
 /usr/include
End of search list.
test.cc:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^
1 error generated.

I have gcc-4.6.3-2.fc16.x86_64 and llvm-2.9-8.fc16.x86_64 . When I
rebuild llvm locally (i.e., with gcc 4.6.3), it finds the include, but I
get the original error again.

Comment 5 Jérôme Benoit 2012-03-24 00:21:30 UTC
Please retest with llvm-2.9-9, It works here. If it works, please give some points to https://admin.fedoraproject.org/updates/llvm-2.9-9.fc16

Comment 6 Fedora Update System 2012-03-24 00:25:11 UTC
Package llvm-2.8-15.fc15:
* should fix your issue,
* was pushed to the Fedora 15 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing llvm-2.8-15.fc15'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2012-4571/llvm-2.8-15.fc15
then log in and leave karma (feedback).

Comment 7 Michel Lind 2012-03-26 10:01:31 UTC
(In reply to comment #1)
> I guess http://llvm.org/bugs/show_bug.cgi?id=9472 needs to be backported.
> This bug exist also in llvm 2.9 in f16.

That is necessary but insufficient; after backporting that patch some of the errors remain. I suspect __decltype also need to be backported; searching for its implementation on the 3.0 branch now.

Comment 8 Fedora Update System 2012-04-05 05:34:39 UTC
llvm-2.9-10.fc16 has been submitted as an update for Fedora 16.
https://admin.fedoraproject.org/updates/llvm-2.9-10.fc16

Comment 9 Michel Lind 2012-04-05 05:37:19 UTC
Fixed in 2.9-10.fc16. I'm switching the affected release to f16, since the codebase is significantly different to 2.8 that reworking the patch is not a trivial undertaking (though I'd welcome such a patch)

Comment 10 Fedora Update System 2012-04-06 21:29:32 UTC
Package llvm-2.9-10.fc16:
* should fix your issue,
* was pushed to the Fedora 16 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing llvm-2.9-10.fc16'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2012-5423/llvm-2.9-10.fc16
then log in and leave karma (feedback).

Comment 11 Fedora Update System 2012-04-13 21:35:32 UTC
llvm-2.9-10.fc16 has been pushed to the Fedora 16 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 12 Mariusz Smykuła 2014-05-14 07:51:48 UTC
I have this problem with clang-3.4-6.fc20.x86_64.rpm

https://github.com/milgner/k290-fnkeyctl/issues/5