g++

g++ and clang++ different behaviour with SFINAE and SFINAE failure

余生长醉 提交于 2019-12-23 09:28:07
问题 A couple of questions for C++11 experts. I'm fighting with SFINAE and I came across a strange case in which g++ (4.9.2), and clang++ (3.5.0) behave differently. I have prepared the following sample code. I'm sorry but I'm unable to do it significantly more concise. #include <string> #include <iostream> #include <typeinfo> #include <type_traits> template <typename X> class foo { private: template <typename R> using enableIfIsInt = typename std::enable_if<std::is_same<X, int>::value, R>::type;

How can I avoid a warning about division-by-zero in this template code?

二次信任 提交于 2019-12-23 08:30:14
问题 I have a class for fixed-point arithmetic, of which this is the salient portion: template <typename I, I S> struct fixed { I value; fixed(I i) : value(i * S) {} template <typename J, J T> fixed(const fixed<J, T> &fx) { if (S % T == 0) value = fx.value * (S / T); else if (T % S == 0) value = fx.value / (T / S); else value = S * fx.value / T; } static_assert(S >= 1, "Fixed-point scales must be at least 1."); }; On GCC 4.4.5, the following line of code: fixed<int, 8> f = fixed<int, 2>(1);

How to set predefined macros in Code::Blocks

China☆狼群 提交于 2019-12-23 07:50:02
问题 Is there a way to set some predefined Macros for my local installation of Code::Blocks. To elaborate on that, basically I would like to have certain blocks compiled only at pc and not anyplace I send the code to. One way to achieve this is as follows: #define MYPC #ifdef MYPC //do something #else // do something else #endif I was to achieve the same thing, but I don't want to include the line #define MYPC and woud like to add this somewhere in the IDE. I know how to do this in Visual Studio,

Fix for bizarre “%a” format behavior with g++ 4.9.1?

眉间皱痕 提交于 2019-12-23 07:48:20
问题 Compiler: 64-bit MinGW G++ 4.9.1 from the Nuwen distro, under Windows 8.1. Code: #ifdef INCLUDE_IOSTREAM # include <iostream> #endif #include <stdio.h> // ::snprintf #include <stdlib.h> // EXIT_SUCCESS, EXIT_FAILURE #include <stdexcept> // std::exception #ifdef snprintf # error snprintf defined as macro #endif #ifdef _MSC_VER auto const snprintf = _snprintf; #endif void test( double const value, int const precision) { char buffer[34]; snprintf( buffer, sizeof( buffer ), "%.*a", precision,

Fix for bizarre “%a” format behavior with g++ 4.9.1?

余生颓废 提交于 2019-12-23 07:48:01
问题 Compiler: 64-bit MinGW G++ 4.9.1 from the Nuwen distro, under Windows 8.1. Code: #ifdef INCLUDE_IOSTREAM # include <iostream> #endif #include <stdio.h> // ::snprintf #include <stdlib.h> // EXIT_SUCCESS, EXIT_FAILURE #include <stdexcept> // std::exception #ifdef snprintf # error snprintf defined as macro #endif #ifdef _MSC_VER auto const snprintf = _snprintf; #endif void test( double const value, int const precision) { char buffer[34]; snprintf( buffer, sizeof( buffer ), "%.*a", precision,

Calls that precede a function's definition cannot be inlined?

吃可爱长大的小学妹 提交于 2019-12-23 07:37:03
问题 The gcc documentation contains the following: When a function is both inline and static, if all calls to the function are integrated into the caller, and the function's address is never used, then the function's own assembler code is never referenced. In this case, GCC does not actually output assembler code for the function, unless you specify the option -fkeep-inline-functions. Some calls cannot be integrated for various reasons (in particular, calls that precede the function's definition

How can I link an .o file using g++

﹥>﹥吖頭↗ 提交于 2019-12-23 07:09:33
问题 I am trying to use g++ to compile a .cc file, and I need it to link a .o file. So I tried: $g++ -o client -I../ipc -L../messages.o client.cc /usr/bin/ld: error: ../messages.o: can not read directory: Not a directory And I have tried: $g++ -o client -I../ipc -l../messages.o client.cc /usr/bin/ld: error: cannot find -l../messages.pb.o $$ ls -l ../messages.o -rw-r--r-- 1 hap497 hap497 227936 2010-02-03 22:32 ../messages.o Can you please tell me how to link in a .o file? Thank you. 回答1: $g++ -o

how-to add “warnings as error” rule to Qt .pro file?

两盒软妹~` 提交于 2019-12-23 07:07:51
问题 When I usually work on a C++ project, one of the first things I do is setting up the "treat warning as errors" on my compiler. When using Qt , qmake generates the Makefile for you and doesn't include this option on the compilation commands. I'm pretty sure there is a way to add such an option (and others) into the generated Makefile but I couldn't figure it out. How would I do that ? I'm using the open-source version of Qt with g++ as the compiler. 回答1: You can use QMAKE_CXXFLAGS in pro file

Include a static cuda library into a c++ project

北慕城南 提交于 2019-12-23 06:58:39
问题 I have a templated static CUDA library which I want to include into a common c++ project. When I include the headers of the library the compiler crashes and says It cannot resolve the CUDA-specific symbols. Of course the g++ compiler cannot interpret these symbols. I know the problem, but I do not know how to fix this problem using the nsight IDE. I'm using nsight for both, the cuda/nvcc library and the c++/g++ project. Console output: make all Building file: ../src/MedPrak.cpp Invoking: GCC

Constexpr is not allowed in declaration of friend template specialization?

拈花ヽ惹草 提交于 2019-12-23 06:44:07
问题 I'm porting a C++14- constexpr codebase from Clang to the latest g++-5.1. Consider the following reduced code snippet of a home-grown bitset class that has been compiling correctly since the halcyon days of Clang 3.3 (almost 2 years now!) #include <cstddef> template<std::size_t> class bitset; template<std::size_t N> constexpr bool operator==(const bitset<N>& lhs, const bitset<N>& rhs) noexcept; template<std::size_t N> class bitset { friend constexpr bool operator== <>(const bitset<N>&, const