Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expression is not an intergral constant clang libc++ threading

I'm trying to compile a really simple thread program on my linux machine(ubuntu), but clang seems to still throw an error at me even when I specify libc++. my program is:

#include <iostream>
#include <thread>

void call_from_thread() {
    std::cout << "Hello, World!" << std::endl;
}

int main()
{
    std::thread t1(call_from_thread);

    t1.join();
    return 0;
}

makefile:

CC=clang++
CFLAGS=-std=c++11 -stdlib=libc++ -pthread -c -Wall
#proper declaration of libc++, but still an error...
LDFALGS=
SOURCES=main.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=bimap

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
        $(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o:
        $(CC) $(CFLAGS) $< -o $@

specific error:

In file included from main.cpp:2:
In file included from /usr/include/c++/4.6/thread:37:
/usr/include/c++/4.6/chrono:666:7: error: static_assert expression is not an
      integral constant expression
      static_assert(system_clock::duration::min()
      ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [main.o] Error 1

I'm not sure why clang isn't using libc++, because if i'm not mistaken clang will compile threads by using this library. Any help is appreciated!

like image 497
Syntactic Fructose Avatar asked May 16 '13 21:05

Syntactic Fructose


1 Answers

In some (earlier) versions of libc++, some functions were not marked as constexpr, which means that they can't be used in static_assert. You should check that system_clock::duration::min() is actually marked that way. [ You'll probably have to check out numeric_limits, since I seem to recall that that was where the problem was ]

The good news is that, if that's the problem, then you can add constexpr to the numeric limits header file yourself; it won't cause any other problems.

like image 115
Marshall Clow Avatar answered Oct 29 '22 15:10

Marshall Clow