LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Building with clang for new C++ standard (https://www.linuxquestions.org/questions/programming-9/building-with-clang-for-new-c-standard-933815/)

tron_thomas 03-10-2012 06:47 PM

Building with clang for new C++ standard
 
I am using the 32-bit version of Fedora 16 on an Intel system. This simple C++ program:

Code:

#include <memory>
#include <iostream>

int main()
{
        auto value = std::make_shared<int>(42);

        std::cout << "The value is " << *value << std::endl;

        return 0;
}

compiles fine using GCC with the following options:

Quote:

g++ -g -Wall -pedantic -ansi -std=c++0x -o Value Value.cpp
When I try to build using clang, I get errors. As near as I can tell clang seems to use the same command line arguments as GCC. I tried building the program using:

Code:

clang++ -g -Wall -pedantic -ansi -std=c++0x -o Value Value.cpp
and I got these errors.

Quote:

In file included from Value.cpp:1:
In file included from /usr/include/c++/4.6.2/memory:63:
In file included from /usr/include/c++/4.6.2/bits/stl_algobase.h:65:
In file included from /usr/include/c++/4.6.2/bits/stl_pair.h:60:
In file included from /usr/include/c++/4.6.2/bits/move.h:53:
/usr/include/c++/4.6.2/type_traits:624:51: error: '_Tp' does not refer to a value
: public integral_constant<bool, __is_trivial(_Tp)>
^
/usr/include/c++/4.6.2/type_traits:622:21: note: declared here
template<typename _Tp>
^
/usr/include/c++/4.6.2/type_traits:625:8: error: expected class name
{ };
^
/usr/include/c++/4.6.2/type_traits:625:8: error: expected '{' after base class list
/usr/include/c++/4.6.2/type_traits:630:59: error: '_Tp' does not refer to a value
: public integral_constant<bool, __is_standard_layout(_Tp)>
^
/usr/include/c++/4.6.2/type_traits:628:21: note: declared here
template<typename _Tp>
^
/usr/include/c++/4.6.2/type_traits:631:8: error: expected class name
{ };
^
/usr/include/c++/4.6.2/type_traits:631:8: error: expected '{' after base class list
/usr/include/c++/4.6.2/type_traits:643:56: error: '_Tp' does not refer to a value
: public integral_constant<bool, __is_literal_type(_Tp)>
^
/usr/include/c++/4.6.2/type_traits:641:21: note: declared here
template<typename _Tp>
^
/usr/include/c++/4.6.2/type_traits:644:8: error: expected class name
{ };
^
/usr/include/c++/4.6.2/type_traits:644:8: error: expected '{' after base class list
/usr/include/c++/4.6.2/type_traits:647:56: error: expected function body after function declarator
typename add_rvalue_reference<_Tp>::type declval() noexcept;
^
/usr/include/c++/4.6.2/type_traits:654:30: error: use of undeclared identifier 'declval'
static decltype(_Tp1(declval<_Args1>()...), __one()) __test(int);
^
/usr/include/c++/4.6.2/type_traits:654:38: error: '_Args1' does not refer to a value
static decltype(_Tp1(declval<_Args1>()...), __one()) __test(int);
^
/usr/include/c++/4.6.2/type_traits:653:43: note: declared here
template<typename _Tp1, typename... _Args1>
^
/usr/include/c++/4.6.2/type_traits:654:46: error: expected expression
static decltype(_Tp1(declval<_Args1>()...), __one()) __test(int);
^
/usr/include/c++/4.6.2/type_traits:654:62: error: C++ requires a type specifier for all declarations
static decltype(_Tp1(declval<_Args1>()...), __one()) __test(int);
~~~~~~ ^
/usr/include/c++/4.6.2/type_traits:668:43: error: use of undeclared identifier 'declval'
static decltype(static_cast<_Tp1>(declval<_Arg1>()), __one())
^
/usr/include/c++/4.6.2/type_traits:668:51: error: '_Arg1' does not refer to a value
static decltype(static_cast<_Tp1>(declval<_Arg1>()), __one())
^
/usr/include/c++/4.6.2/type_traits:667:40: note: declared here
template<typename _Tp1, typename _Arg1>
^
/usr/include/c++/4.6.2/type_traits:668:58: error: expected expression
static decltype(static_cast<_Tp1>(declval<_Arg1>()), __one())
^
/usr/include/c++/4.6.2/type_traits:669:2: error: C++ requires a type specifier for all declarations
__test(int);
^
/usr/include/c++/4.6.2/type_traits:694:48: error: use of undeclared identifier 'declval'
{ static const bool __value = noexcept(_Tp(declval<_Args>()...)); };
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
What is needed to use clang for building C++ program that use features from the new C++ standard?

dwhitney67 03-11-2012 01:29 PM

Have you looked at this? http://clang.llvm.org/cxx_status.html

tron_thomas 03-11-2012 03:40 PM

I believe I have seen that page or something similar to it. Curiously, the page says nothing about std::shared_ptr. Being that I'm using the lastest version of Fedora, I have a fairly recent version of clang, 2.9. I would think the features I'm trying to use in this simple program would have been supported, yet I'm getting many errors. Seems like things should work better, or perhaps different command line arguments are needed.


All times are GMT -5. The time now is 09:29 PM.