g++

std::vector::emplace_back bug when returning references (C++17)

旧城冷巷雨未停 提交于 2021-01-27 15:31:01
问题 I've been trying to trace a bug for 10+ hours now, and by now I'm starting to think that the bug can't be on my side. However, I have a feeling it could be me who's just forgetting or misunderstanding something. I have a class member of type std::vector called temp_materials, and inside the constructor (when temp_materials is still empty), this code runs: Material &stonewallbug = temp_materials.emplace_back(resource_lib.get_shader("DeferredGeometryShader")); stonewallbug.set_texture("texture

why does c++ std::min can't use a static field as its parameter when compile on O0?

强颜欢笑 提交于 2021-01-27 14:22:29
问题 same code, compile with O0, it will report an error: //============================================================================ // Name : test.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <stdint.h> using namespace std; class foo{ static const int64_t MAX_THREAD_NUM = 10 * 1000; public: void test(); }; void foo:

Implicitly defined constructor deleted due to variant member, N3690/N4140 vs N4659/N4727

纵饮孤独 提交于 2021-01-27 12:12:32
问题 My story starts off the same as this person's here: Unions in C++11: default constructor seems to be deleted The resolution here (now about three years old) is a bit unsatisfactory, because the "Digging into the standard" that the author did ended up with concluding that the behavior was as described in the standard, but unfortunately the quote is from a Note , and those are supposed to be non-normative (I've been told). Anyways, there's a link to an old bug report on gcc that is claimed to

C++ Linux: lib1 shared library uses shared library lib2, main program uses lib1, why shall it be linked to lib2?

邮差的信 提交于 2021-01-20 13:43:29
问题 I'm using g++ (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609. I have a shared library lib2 : lib2.h: #pragma once class Lib2 { public: Lib2(); }; lib2.cpp: #include "lib2.h" Lib2::Lib2() { } I have a shared library lib1 that uses and so needs lib2 : lib1.h: #pragma once class Lib1 { public: Lib1(); }; lib1.cpp: #include "lib1.h" #include "lib2.h" Lib1::Lib1() { Lib2 lib2; } Now I have a program that uses lib1 , and so does not "directly" use lib2 but would need it at runtime. main.cpp:

C++ Linux: lib1 shared library uses shared library lib2, main program uses lib1, why shall it be linked to lib2?

一个人想着一个人 提交于 2021-01-20 13:42:18
问题 I'm using g++ (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609. I have a shared library lib2 : lib2.h: #pragma once class Lib2 { public: Lib2(); }; lib2.cpp: #include "lib2.h" Lib2::Lib2() { } I have a shared library lib1 that uses and so needs lib2 : lib1.h: #pragma once class Lib1 { public: Lib1(); }; lib1.cpp: #include "lib1.h" #include "lib2.h" Lib1::Lib1() { Lib2 lib2; } Now I have a program that uses lib1 , and so does not "directly" use lib2 but would need it at runtime. main.cpp:

Using dlsym in c++ without extern “C”

北城以北 提交于 2021-01-19 06:04:48
问题 I have a system in which I give the user a function prototype and the user has to implement it. Now, I compile this file using g++ and load it dynamically using dlopen and dlsym to process it further. Now, I read here: c++ dlopen mini-howto that to load c++ functions we have to use extern "C" before the function. Now, the problem is, I do not want to show the user how things are working. I do not want to show the user extern "C" before the function. Is there any way to avoid it? 回答1: You can

C++ using g++, no result, no print

时光总嘲笑我的痴心妄想 提交于 2021-01-05 12:27:21
问题 I'm slowly moving from using Python to using C++ and I don't understand how to run any code. I'm using the g++ compiler, but I get no results from my functions. // arrays example #include <iostream> using namespace std; int foo [] = {16, 2, 77, 40, 12071}; int n, result=0; int main () { for ( n=0 ; n<5 ; ++n ) { result += foo[n]; } cout << result; return 0; } If I run this example inside VSCode and specify that I want to use g++ compiler it comes back with: Terminal will be reused by tasks,

C++ using g++, no result, no print

本秂侑毒 提交于 2021-01-05 12:24:48
问题 I'm slowly moving from using Python to using C++ and I don't understand how to run any code. I'm using the g++ compiler, but I get no results from my functions. // arrays example #include <iostream> using namespace std; int foo [] = {16, 2, 77, 40, 12071}; int n, result=0; int main () { for ( n=0 ; n<5 ; ++n ) { result += foo[n]; } cout << result; return 0; } If I run this example inside VSCode and specify that I want to use g++ compiler it comes back with: Terminal will be reused by tasks,

C++ using g++, no result, no print

戏子无情 提交于 2021-01-05 12:24:40
问题 I'm slowly moving from using Python to using C++ and I don't understand how to run any code. I'm using the g++ compiler, but I get no results from my functions. // arrays example #include <iostream> using namespace std; int foo [] = {16, 2, 77, 40, 12071}; int n, result=0; int main () { for ( n=0 ; n<5 ; ++n ) { result += foo[n]; } cout << result; return 0; } If I run this example inside VSCode and specify that I want to use g++ compiler it comes back with: Terminal will be reused by tasks,

Is there a `clang++:-Wunused-lambda-capture` equivalent warning in/being developed for GCC?

旧城冷巷雨未停 提交于 2021-01-05 07:58:46
问题 Background I sometimes run into code that use the following dummy lambda-capture (instead of e.g. (void)x; , ... foo(int /* x */) or ... foo([[maybe_unused]] int x) in C++17) in order to remedy an unused variable warning: void foo(int x) { [&x]{}(); } Now, this is not really a remedy, as it passes the warning over from the current scope to the lambda capture instead, but afaik, GCC has no diagnostic to flag this, whereas e.g. Clang (as of 5.0) emits the unused-lambda-capture warning, if