libstdc++

std::istream operator exception reset / not thrown

喜欢而已 提交于 2019-11-27 08:05:52
问题 I'm not sure about how to use std::istream::exception according to the standard , to let std::istream::operator>> throw an exception if it can't read the input into a variable, e.g. double. The following code has different behavior with clang/libc++ and gcc/libstdc++: #include <iostream> #include <cassert> int main () { double foo,bar; std::istream& is = std::cin; is.exceptions(std::istream::failbit); is >> foo; //throws exception as expected with gcc/libstdc++ with input "ASD" std::cout <<

What Effect Would LWG2349 Have?

喜夏-厌秋 提交于 2019-11-27 07:45:15
问题 While libstdc++ does not, libc++ does follow the standard which states that passing ios_base::failbit to basic_istream::exceptions has no effect on formatted input. For example this code: istringstream is{"ASD"}; double foo; is.exceptions(istream::failbit); try { is >> foo; cout << foo << endl; } catch(ios_base::failure& fail) { cout << "ouch\n"; } Would result in: "ouch" on libstdc++ "0" on libc++ My reading of LWG2349 is that it would cause basic_istream to not throw on any formatted input.

Linking g++ 4.8 to libstdc++

﹥>﹥吖頭↗ 提交于 2019-11-27 04:53:57
I downloaded and built gcc 4.8.1 on my desktop, running 64-bit Ubuntu 12.04. I built it out of source, like the docs recommend, and with the commands ../../gcc-4.8.1/configure --prefix=$HOME --program-suffix=-4.8 make make -k check make install It seemed to pass all the tests, and I installed everything into my home directory w/ the suffix -4.8 to distinguish from the system gcc, which is version 4.6.3. Unfortunately when I compile c++ programs using g++-4.8 it links to the system libc and libstdc++ rather than the newer ones compiled from gcc-4.8.1. I downloaded and built gcc 4.8 because I

Why does libc++'s implementation of std::string take up 3x memory as libstdc++?

雨燕双飞 提交于 2019-11-27 04:25:42
Consider the following test program: #include <iostream> #include <string> #include <vector> int main() { std::cout << sizeof(std::string("hi")) << " "; std::string a[10]; std::cout << sizeof(a) << " "; std::vector<std::string> v(10); std::cout << sizeof(v) + sizeof(std::string) * v.capacity() << "\n"; } Output for libstdc++ and libc++ respectively are: 8 80 104 24 240 264 As you can see, libc++ takes 3 times as much memory for a simple program. How does the implementation differ that causes this memory disparity? Do I need to be concerned and how do I workaround it? Here is a short program to

Using memory sanitizer with libstdc++

◇◆丶佛笑我妖孽 提交于 2019-11-27 02:38:10
问题 I wish to use the -fsanitize=memory flag in clang to analyse a program like the following: #include <string> #include <iostream> #include <fstream> using namespace std; void writeToFile(){ ofstream o; o.open("dum"); o<<"test"<<endl; //The error is here. //It does not matter if the file is opened this way, //or with o("dum"); o.close(); } int main(){ writeToFile(); } As far as I know, this program is correct, but when I use clang++ san.cpp -fsanitize=memory It fails (at runtime) with: UMR in _

Linking libstdc++ statically: any gotchas?

六月ゝ 毕业季﹏ 提交于 2019-11-26 23:21:18
I need to deploy a C++ application built on Ubuntu 12.10 with GCC 4.7's libstdc++ to systems running Ubuntu 10.04, which comes with a considerably older version of libstdc++. Currently, I'm compiling with -static-libstdc++ -static-libgcc , as suggested by this blog post: Linking libstdc++ statically . The author warns against using any dynamically-loaded C++ code when compiling libstdc++ statically, which is something I haven't yet checked. Still, everything seems to be going smoothly so far: I can make use of C++11 features on Ubuntu 10.04, which is what I was after. I note that this article

libstdc++ GLIBCXX version errors

独自空忆成欢 提交于 2019-11-26 23:11:32
问题 when I compile a c++ program in my computer using g++ and transfer the executable to run it on my university server, I get ./main: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by ./main) ./main: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by ./main) ./main: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by ./main) The program runs well on my computer, and I don't have privileges to install any new software on my

Using std::array with initialization lists

橙三吉。 提交于 2019-11-26 22:26:27
Unless I am mistaken, it should be possible to create a std:array in these ways: std::array<std::string, 2> strings = { "a", "b" }; std::array<std::string, 2> strings({ "a", "b" }); And yet, using GCC 4.6.1 I am unable to get any of these to work. The compiler simply says: expected primary-expression before ',' token and yet initialization lists work just fine with std::vector. So which is it? Am I mistaken to think std::array should accept initialization lists, or has the GNU Standard C++ Library team goofed? std::array is funny. It is defined basically like this: template<typename T, int

IOS7 (only) stdlibc++ linking issue

大兔子大兔子 提交于 2019-11-26 22:06:10
I need help. I had a framwork which was using stdc++ like std:string. Now when i have created new app for IOS7 only there is problem with linking this framework because of problems with stdc++ lib: Undefined symbols for architecture armv7 "std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage", referenced from ... I have find out something strange that when i change the Deplyment target to ios6 in this app all is working fine. With ios7 i see errors. I already have flag set in other linker flags: -lstdc++ Any idea what ami doing wrong? Just an update on this answer: This step is very

Forcing or preventing use of a particular minor version of libstdc++

╄→尐↘猪︶ㄣ 提交于 2019-11-26 21:37:27
问题 In order to make use of C++11 and c++14 features I have an application compiled using a newer version of gcc (4.9.1) and thus an newer version of libstdc++. The application consists of many small programs so I am linking with libstdc++ as a shared library rather than a static one (i.e. I don't wish to use -static-libstdc++) I wish to ship the new version of libstdc++ with the application under /opt//lib64 (note: that this is specifically allowed under an exception to the GPL) The new version