Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
1 answer
146 views

Does std::unique_ptr support fancy pointers?

Can std::unique_ptr manage pointers only, or fancy pointers (pointer-like types) too? I assume "fancy pointers too", because for resources like files/sockets, fancy pointers can be a great ...
DoZerg's user avatar
  • 323
0 votes
0 answers
84 views

Fixing a complicated class w/union + struct

I have a somewhat complex class that compiles with Visual Studio 2019 with no issues. I'm trying to compile it now in GCC. It gives me an error because I'm using a class within an anonymous union, ...
KiraHoneybee's user avatar
1 vote
2 answers
140 views

Why exception can not be caught on windows by msvc but on Linux by GCC [duplicate]

The same files on Windows and Linux as follow: std_exp.cpp #include <iostream> #include <string> #include <stdexcept> using namespace std; int main() { try { std::...
Monhde Sau Hung's user avatar
0 votes
1 answer
48 views

Unexpected output of C++11 regex?

#include <iostream> #include <regex> #include <string> #include <vector> using namespace std; #define debug(exp) do { cout << #exp << ": " << (exp) &...
dizzy x's user avatar
0 votes
0 answers
53 views

How can I force g++ 5.4.0 to only use system headers that do not require C++11 support?

I am compiling C and C++ code for several platforms using Docker images provided by a different team. The other team provides different Docker images for each platform, and there is no uniformity as ...
Shane Bishop's user avatar
  • 4,680
8 votes
1 answer
122 views

Replacing throw(...) with noexcept(...) - ABI safe across language standards?

Suppose I'm using a library that has a declaration like this in its header: #if __cplusplus >= 201703L // C++17 or newer #define _NOTHROW noexcept(true) #define _THROWS(x) noexcept(false) #...
Noam Elul's user avatar
  • 348
0 votes
1 answer
110 views

Why does the function recursion seem to make the conditions work crazily?

First at all: test_container, in the following code, is a function that is only used for "debugging" purposes. There is no real use on my working project. The real function is called ...
Anderson Duarte's user avatar
2 votes
0 answers
102 views

Prevent reordering of prefetch instruction in c++

Usecase: I have an SPSC queue in multi-thread setup, where I want to prefetch the write_index's mempool on a successful pop. Following is my original implementation: void process() { if(spsc_queue-&...
Akash's user avatar
  • 969
0 votes
0 answers
99 views

Re-implementation of strptime in C++11 leads to strange behavior with VisualStudio

In order to have a fully portable code Win/Linux, I tried to re-implement a strptime like function using C++11 and all the hints I found on stackoverflow (and others). But I see a strange behaviors (...
Captain'Flam's user avatar
0 votes
2 answers
441 views

With C++11, how can I generate a warning message in a manner that works in gcc, clang, and MSVC?

When compiling C++11 using clang or gcc, I can generate a warning message at compilation time using: #warning My message here This doesn't work on Windows when I use MSVC, though. How can I ...
Bri Bri's user avatar
  • 2,120
2 votes
0 answers
213 views

How to suppress warning -Wignored-attributes using __m128 on templates?

I've this basic code: #include <iostream> #include <emmintrin.h> template <typename T> struct SRCDecimator { SRCDecimator() { } }; int main() { SRCDecimator<__m128&...
markzzz's user avatar
  • 47.8k
1 vote
0 answers
100 views

Why is compiler mis-stating namespace?

Doing some C++ development after a good four years in Python, it appears I'm a little rusty. I have three files in my very cut-down example (the actual code is much larger but this example still ...
paxdiablo's user avatar
  • 879k
0 votes
1 answer
116 views

Why gcc does not create a new variable?

I have such code: static const char kFmt[] = "some string: - %s"; char buf[sizeof(kFmt) + 10]; snprintf(buf, sizeof(buf), kFmt, "string"); It looks like arm gcc 6.3.0 does not ...
Konstantin T.'s user avatar
4 votes
1 answer
133 views

Why does the correct implementation of std::addressof require compiler support?

From possible implementation of std::addressof on https://en.cppreference.com/w/cpp/memory/addressof, it states that "correct implementation of std::addressof require compiler support". Why ...
cpp's user avatar
  • 321
0 votes
1 answer
170 views

Error when using C++11 List Initialization Syntax g++ compiler

When I use list initialization to init my class members, the complier complains it's a function. The g++ output: $ g++ main.cpp -o main In file included from main.cpp:1: ./Cat.h:9:9: error: function ...
Shaowen Zhu's user avatar
1 vote
1 answer
101 views

Why directly modifying basic_string.h does not recompile

I am not so familiar with std containers. It seems basic_string.h is a template and can be modified to use directly without recompile libstdc++. Am I correct on this? Thanks for helps.
GGinside's user avatar
2 votes
1 answer
975 views

TWS API Linux - Segmentation fault - __bid64_to_string

Running Cpp sample client out of the box. I receive a segmentation fault. 0x00005555555efba6 in __bid64_to_string () Have sourced this function to client file to Decimal.h extern "C" void ...
Andrew Bannerman's user avatar
2 votes
1 answer
84 views

condition_variable::wait_until passes through unexpectedly g++ (9.4.0)

I am trying to understand the behaviour of condition_variable::wait_until. I have two pieces of code which I expect will wait one second and then exit. However, when I execute the programs (compiled ...
stephematician's user avatar
0 votes
1 answer
192 views

Old-style vs C++11 attribute syntax

By old-style I mean __attribute__((visibility("default"))) By C++11 syntax I mean [[gnu::visibility("default")]] I am working on huge codebase which must stay buildable with MSVC, ...
Ibraim Ganiev's user avatar
0 votes
0 answers
26 views

gcc compiler not able to find function definition in code file (.cpp)? [duplicate]

I want to compile my C++ code locally. I have separated it into header files (.hpp) and code files (.cpp) galaxy.hpp #pragma once #include <vector> namespace Edge { namespace Galaxy { ...
Senor Maldona's user avatar
4 votes
4 answers
235 views

How to prevent floating-point being implicitly converted to integral value at function call in c++? [duplicate]

How to prevent floating-point being implicitly converted to integral value at function call? #include <iostream> void fn(int x) { std::cout<<"fn("<<x<<")\n&...
Supreeto's user avatar
  • 308
0 votes
0 answers
32 views

When I am running code it is this error how to fix it?

Please help me to resolve this error. gcc compiler is not working in ventura macOS . When I am running code it is showing that update your include path. Please help me how gcc will be working in ...
Aniruddha Das's user avatar
0 votes
1 answer
120 views

Undefined reference to `FastPForLib:..' while linking FastPForlib

Any suggestion regarding the following query would be appreciated. I have tried everything and am still struck with this error. The library (FastPFor) works fine with the visual studio solution; the ...
TopLearner's user avatar
2 votes
0 answers
626 views

Is this a bug in gcc 11.2.1 related to _GLIBCXX_USE_CXX11_ABI?

The following C++ code fails to compile on gcc 11.2.1 on CentOS 7.2.2009 (available through Software Collections only) using the following command : Command : scl enable devtoolset-11 'g++ -std=c++11 ...
johngreen's user avatar
  • 2,734
0 votes
2 answers
4k views

Cannot install fastText because gcc 7.3.1 does not support C++11 on Amazon Linux

I need to install a system that uses fastText onto an Amazon Linux machine. As practice, I have been trying to build fastText from source inside an Amazon Linux 2 docker image. I noticed gcc wasn't ...
icedwater's user avatar
  • 4,877
3 votes
0 answers
310 views

How can I build the boost libraries 1_72_0 on a windows host for a linux target?

Trying to build the boost libraries, I followed the steps: open cmd in boost_1_72_0 folder bootstrap.bat gcc set cfalgs, cxxflags and linker flags to use the sysroot folder that came with the ...
Vulsan Bianca's user avatar
10 votes
2 answers
227 views

Forward-declaration of enum member of template-specialization - fails with GCC

I know that, generally, we can forward-declare enums in C++11. So, why does this: enum kind_t { kind1, kind2 }; template <kind_t Kind> struct foo {}; template <> struct foo<kind1> {...
einpoklum's user avatar
  • 130k
0 votes
1 answer
399 views

Build boost from source with manually built gcc compiler in cluster

I am trying to compile Boost 1.79.0 in a cluster using the GCC compiler version 12.1.0 that I have compiled manually since the GCC version of the cluster is very old. After compiling GCC, I have ...
K. Mountris's user avatar
5 votes
1 answer
592 views

c++ complains about __VA_ARGS__

The following code has been compiled with gcc-5.4.0 with no issues: % gcc -W -Wall a.c ... #include <stdio.h> #include <stdarg.h> static int debug_flag; static void debug(const char *fmt,...
Mark's user avatar
  • 6,434
1 vote
1 answer
159 views

Question about std::make_pair & std::atomic_bool

Why this code snippet does not compile with gcc 4.9.0, whereas it works well with gcc 12.1. The same code snippet is compiled with the same option. Here is the code snippet: #include<atomic> #...
John's user avatar
  • 3,424
1 vote
0 answers
123 views

std::regex constructor throwing std::regex_error with what(): regex_error

I need to get some strings from a given line as below: {"username":"wrongpass", "password":"abc", "email":"[email protected]"} To be more ...
nine-point-eight's user avatar
0 votes
0 answers
22 views

Making a static map with pair as a key [duplicate]

Trying to solve a leetcode problem. Here's the link. In the problem I am trying to make a static map with pair as a key. As I removed the static keyword, the code is working perfectly fine. But in ...
Aarsh's user avatar
  • 420
3 votes
1 answer
1k views

Getting Arduino IDE to compile for C++14

I've been looking to modify the build flags under Arduino's IDE 1.x, or even the Arduino CLI (which I haven't used but am willing to adopt) such that I can undefine -std=gnu++11 and instead define -...
honey the codewitch's user avatar
0 votes
0 answers
235 views

Trying to complie ICU by unicode on RHEL7 system

I am trying to install ICU from git clone repo. I run ./cnfigure and everything seems fine. When i go to run make I get a bunch of errors. I am new to Linux and cannot find any fixes anywhere. it ...
Kilo 's user avatar
1 vote
1 answer
117 views

Standard hash with variadic template

I have the following code: namespace foo { template<typename ...Types> class Pi { }; } namespace std { template<> //line offending gcc 8.3.1 template<typename ...Types&...
greywolf82's user avatar
  • 22.2k
1 vote
1 answer
519 views

Get GCC to Remove C++ 11 Flag in Mangled Name

I'm debugging a build that links against JsonCpp and I get a linker error where the demangled name it's trying to link to is _ZNK4Json6Reader25getFormattedErrorMessagesB5cxx11Ev and the one the ...
John Stanford's user avatar
2 votes
1 answer
77 views

What are the rules for integral promotions in initialization lists and is this a false positive warning in GCC or rather C++ limitation?

In the below code we essentially assign the same value to 4 unsigned char variables in 4 different ways - but one of them using the initialization list issues a warning: warning: narrowing conversion ...
RnR's user avatar
  • 2,115
0 votes
0 answers
63 views

Overload Resolution: Templatized member function vs friend function for stream operator

Suppose we have this scenario(maybe a little bit artificial) class OStream { virtual void f1() = 0; ... virtual void f10() = 0; template<typename T> OStream& operator<&...
Hayk's user avatar
  • 49
3 votes
1 answer
2k views

Producing a library with a recent gcc and consuming it with an older gcc - Why are there issues despite the same C++ version?

Don't ask me why I am doing what I am doing... that would be a long story. For now, the purpose of this post is to learn and to understand why things don't work the way I expect. Possibly my ...
DaveC's user avatar
  • 167
0 votes
2 answers
531 views

std::unordered_map ordering change while traversing during different executions

Suppose there is class Heavy with a bunch of user-defined compound class members. One of that, let's name it m_hashMap, has std::unordered_map<unsigned int, std::vector<CompoundClass>> ...
Hayk's user avatar
  • 49
3 votes
1 answer
178 views

Program works on GCC 7.5 on PC but not on online compiler

I have the following program that compiles successfully on my machine using GCC 7.5.0 but when i try out the program here the program doesn't work. class Foo { friend void ::error() { } }; int ...
user12002570's user avatar
1 vote
0 answers
922 views

QNX7 and GCC 5.4.0 and CMAKE (fatal error: map: No such file or directory compilation terminated.)

I use CMAKE to cross compile my code for QNX6.5 and using gcc/g++ 4.4.2 I added a new tool chain file for QNX7 using gcc/g++ 5.4.0. My issue is that I am failing the build on standard includes like ...
Darren C. Gladney's user avatar
0 votes
0 answers
42 views

error: cannot bind non-const lvalue reference of type ** to an rvalue of type ** [duplicate]

I am working on compiling some old api code that was written back in mid to late 90's, it is written in C++98 and I am using GCC on linux. I have this line of offending code: UnpackCommunityData(data....
user3654535's user avatar
1 vote
0 answers
494 views

gcc and clang: thread library is successfully included but nothing won't be compiled with that

I've got specific error that I haven't encountered before. Before I'll start, I need to say that I work on a server and have no root rights. /usr/bin and /usr/local/bin are missing many packages and ...
MadMax's user avatar
  • 41
3 votes
1 answer
922 views

VSCode C++ Debugger Mac not Linking CPP files

I am trying to run the debugger for a simple "hello world" like program but am running into linking errors. I only have 3 files, Log.h, Log.cpp, Main.cpp: Log.h #pragma once void InitLog(); ...
everwitt7's user avatar
  • 321
-1 votes
1 answer
58 views

C++11 is not executing switch correctly when variable is declared in case block

Consider the snippet below. If I compile this with GCC/C++11 then I expect that if I call this with e.g. var=2 that that block is executed. Anyway I expect at least one of the 3 switch blocks are ...
robert's user avatar
  • 2,027
1 vote
3 answers
420 views

Replace C++ class/static method with preprocessor?

I'd like to use the built-in compiler checks to verify format strings of a custom logging framework to catch the odd runtime crash due to mismatching format string <-> parameters in advance. ...
ATV's user avatar
  • 4,486
1 vote
1 answer
131 views

Why is my exception sliced to base class if I catch it with reference to base class?

So I've written a small C++ class as follows: class bad_hmean : public std::logic_error { const char *nature_; char *what_; public: bad_hmean(const char *fname); ~bad_hmean() { ...
Nikola Vugdelija's user avatar
0 votes
1 answer
62 views

Why does std::regex_match generate different results

I'm trying to use std::regex to validate some variables from a file in my c++11 project. For now I need to validate if a string is a valid URL or not. Here is my code: https://godbolt.org/z/4Pn9eYEce ...
Yves's user avatar
  • 12.2k
2 votes
1 answer
343 views

g++ compiler gives me errors with -std=c++11 flag, but it compiles fine with -std=gnu++11. what does this mean?

I'm maintaining an old server at work, which is running on CentOS6(gcc (GCC) 4.4.7, C++98) and I was trying to migrate it to CentOS7(gcc (GCC) 4.8.5) with C++11. At first, I tried to compile with a ...
Jon Phil's user avatar

1
2 3 4 5
34