g++

Code using SFINAE working with GCC but not with Clang

拈花ヽ惹草 提交于 2021-02-10 05:12:52
问题 I'm trying to use SFINAE in C++11 to implement a serialization library. My code works fine with GCC but not with Clang. I've reduced it here to a minimal code: template <typename A, typename T> constexpr auto has_save_method(A& ar, T& t) -> decltype(t.save(ar), bool()) { return true; } template<class A, typename T, bool has_save> struct saver; template<class A, typename T> struct saver<A,T,true> { static void apply(A& ar, T& t) { t.save(ar); } }; class MyClass { public: template<typename A>

Why doesn't g++ -Wconversion warn about conversion of double to long int when double is constant?

ε祈祈猫儿з 提交于 2021-02-09 07:15:29
问题 If I pass a double to a function requiring long, g++ warns of conversion problem, but if I pass a const double to a function requiring long, g++ is happy. The warning is the following: warning: conversion to ‘long int’ from ‘double’ may alter its value [-Wconversion] I would like g++ to give me a warning whether I pass a double or a const double. How would I do so? I have makefile and some code you can run. I like to turn on as many warnings as I can, but perhaps one is implicitly shutting

Why doesn't g++ -Wconversion warn about conversion of double to long int when double is constant?

怎甘沉沦 提交于 2021-02-09 07:15:12
问题 If I pass a double to a function requiring long, g++ warns of conversion problem, but if I pass a const double to a function requiring long, g++ is happy. The warning is the following: warning: conversion to ‘long int’ from ‘double’ may alter its value [-Wconversion] I would like g++ to give me a warning whether I pass a double or a const double. How would I do so? I have makefile and some code you can run. I like to turn on as many warnings as I can, but perhaps one is implicitly shutting

GCC not performing loop invariant code motion

爷,独闯天下 提交于 2021-02-09 07:12:33
问题 I decided to check the result of loop invariant code motion optimization using g++. However, when I compiled the following code with -fmove-loop-invariants and analysed its assembly, I saw that k + 17 calculation is still performed in the loop body. What could prevent the compiler from optimizing it? May be the compiler concludes that it is more efficient to recalculate k + 17 ? int main() { int k = 0; std::cin >> k; for (int i = 0; i < 10000; ++i) { int n = k + 17; // not moved out of the

Why doesn't g++ -Wconversion warn about conversion of double to long int when double is constant?

☆樱花仙子☆ 提交于 2021-02-09 07:12:27
问题 If I pass a double to a function requiring long, g++ warns of conversion problem, but if I pass a const double to a function requiring long, g++ is happy. The warning is the following: warning: conversion to ‘long int’ from ‘double’ may alter its value [-Wconversion] I would like g++ to give me a warning whether I pass a double or a const double. How would I do so? I have makefile and some code you can run. I like to turn on as many warnings as I can, but perhaps one is implicitly shutting

Why doesn't g++ -Wconversion warn about conversion of double to long int when double is constant?

老子叫甜甜 提交于 2021-02-09 07:11:13
问题 If I pass a double to a function requiring long, g++ warns of conversion problem, but if I pass a const double to a function requiring long, g++ is happy. The warning is the following: warning: conversion to ‘long int’ from ‘double’ may alter its value [-Wconversion] I would like g++ to give me a warning whether I pass a double or a const double. How would I do so? I have makefile and some code you can run. I like to turn on as many warnings as I can, but perhaps one is implicitly shutting

Why doesn't g++ -Wconversion warn about conversion of double to long int when double is constant?

為{幸葍}努か 提交于 2021-02-09 07:10:17
问题 If I pass a double to a function requiring long, g++ warns of conversion problem, but if I pass a const double to a function requiring long, g++ is happy. The warning is the following: warning: conversion to ‘long int’ from ‘double’ may alter its value [-Wconversion] I would like g++ to give me a warning whether I pass a double or a const double. How would I do so? I have makefile and some code you can run. I like to turn on as many warnings as I can, but perhaps one is implicitly shutting

g++ breaking change in std::filesystem::last_write_time

喜欢而已 提交于 2021-02-08 17:38:07
问题 With recent OS upgrade I noticed that small part of my code stopped compiling - it seems the reason is switching from g++-8 to g++-9 . This code is compiling alright on g++ 8.3.0 (verified this using gcc:8.3 image from Dockerhub) #include <filesystem> #include <chrono> int main() { namespace fs = std::filesystem; using namespace std::chrono_literals; std::filesystem::last_write_time("test", std::chrono::system_clock::now() - 5min); } On g++ 9.1.0 it fails with: test.cpp: In function 'int main

Visual Studio 2019 rejects `bool concept` while gcc 8 doesn't compile concepts without `bool`

删除回忆录丶 提交于 2021-02-08 09:58:06
问题 I thought c++ concepts is a better method to write c++ templated code with better error messages and faster compile times , so I upgraded Visual Studio to 2019 and still waiting for clang to support concepts however I tested some simple code with msvc from visual studio 2019 and g++ 8 from mingw-w64 and I'm having some trouble. This is the test: #include <iostream> using namespace std; // this compiles under g++ 8 but not visual studio 2019 template <class T> bool concept CharT = std::is_same

Getting undefined reference when trying to build a pybind11 project using gcc

Deadly 提交于 2021-02-08 06:40:54
问题 I am trying to build a C++ static library in Linux (Ubuntu 18.04 in my case) using GCC using a Makefile . I noticed the issue is not with the makefile itself but the way I'm trying to compile and build with GCC. Before I explain a bit more on the GCC side, here is how my current project hierarchy looks like. The project uses Pybind11 header only library which resides in the External_Libraries directory. My class definition and implementation, naming Core.h and Core.cpp reside in Internal