standards-compliance

Narrowing conversion to bool in list-initialization - strange behaviour

风格不统一 提交于 2019-11-27 01:32:02
问题 Consider this piece of C++11 code: #include <iostream> struct X { X(bool arg) { std::cout << arg << '\n'; } }; int main() { double d = 7.0; X x{d}; } There's a narrowing conversion from a double to a bool in the initialization of x . According to my understanding of the standard, this is ill-formed code and we should see some diagnostic. Visual C++ 2013 issues an error: error C2398: Element '1': conversion from 'double' to 'bool' requires a narrowing conversion However, both Clang 3.5.0 and

Does constexpr imply inline?

我的梦境 提交于 2019-11-27 01:14:57
Consider the following inlined function : // Inline specifier version #include<iostream> #include<cstdlib> inline int f(const int x); inline int f(const int x) { return 2*x; } int main(int argc, char* argv[]) { return f(std::atoi(argv[1])); } and the constexpr equivalent version : // Constexpr specifier version #include<iostream> #include<cstdlib> constexpr int f(const int x); constexpr int f(const int x) { return 2*x; } int main(int argc, char* argv[]) { return f(std::atoi(argv[1])); } My question is : does the constexpr specifier imply the inline specifier in the sense that if a non-constant

Java reflection: Is the order of class fields and methods standardized?

泪湿孤枕 提交于 2019-11-26 22:20:25
Using reflection on Java classes to access all field, methods, and so on: Is there a standardized order of these elements (which is specified in some standard)? Of course, I could check it empirically, but I need to know if it's always the same. EDIT: I waited for the question: What I need the order for ;) Long story short: I have JAXB-annotated classes, and want no represent these classes visually. While the order of XML attributes is neither relevant for the XML standard, nor for JAXB, I want to have a certain order the XML attributes for the visual representation. For example: start comes

Why does std::cout convert volatile pointers to bool?

守給你的承諾、 提交于 2019-11-26 21:04:38
If you try to cout a pointer to a volatile type, even a volatile char pointer where you would normally expect cout to print the string, you will instead simply get '1' (assuming the pointer is not null I think). I assume output stream operator<< is template specialized for volatile pointers, but my question is, why? What use case motivates this behavior? Example code: #include <iostream> #include <cstring> int main() { char x[500]; std::strcpy(x, "Hello world"); int y; int *z = &y; std::cout << x << std::endl; std::cout << (char volatile*)x << std::endl; std::cout << z << std::endl; std::cout

Does a dot have to be escaped in a character class (square brackets) of a regular expression?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 20:11:51
A dot . in a regular expression matches any single character. In order for regex to match a dot, the dot has to be escaped: \. It has been pointed out to me that inside square brackets [] a dot does not have to be escaped. For example, the expression: [.]{3} would match ... string. Doesn't it, really? And if so, is it true for all regex standards? lilactiger89 In a character class (square brackets) any character except ^ , - , ] or \ is a literal. This website is a brilliant reference and has lots of info on the nuances of different regex flavours. http://www.regular-expressions.info

Clean way to launch the web browser from shell script?

不想你离开。 提交于 2019-11-26 18:53:25
问题 In a bash script, I need to launch the user web browser. There seems to be many ways of doing this: $BROWSER xdg-open gnome-open on GNOME www-browser x-www-browser ... Is there a more-standard-than-the-others way to do this that would work on most platforms, or should I just go with something like this: #/usr/bin/env bash if [ -n $BROWSER ]; then $BROWSER 'http://wwww.google.com' elif which xdg-open > /dev/null; then xdg-open 'http://wwww.google.com' elif which gnome-open > /dev/null; then

Defined behaviour for expressions

◇◆丶佛笑我妖孽 提交于 2019-11-26 17:44:54
问题 The C99 Standard says in $6.5.2. Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored . (emphasis by me) It goes on to note, that the following example is valid (which seems obvious at first) a[i] = i; While it does not explicitly state what a and i are. Although I believe it does not, I'd like to know whether this example

How to programmatically turn off quirks mode in IE8 WebBrowser control?

依然范特西╮ 提交于 2019-11-26 16:24:49
问题 I want to use IE8 as a WebBrowser control in a C# application. How can I disable "quirks mode" and force IE into standards compliance (as far as it is implemented)? 回答1: I think the issue you're facing is described in IEBlog: WebBrowser Control Rendering Modes in IE8: While webmasters can easily alter their site to render properly in the new version of IE, many software vendors do not have the resources to instantly push out new versions of their applications with updated internal pages. In

Is main() really start of a C++ program?

旧时模样 提交于 2019-11-26 10:13:45
The section $3.6.1/1 from the C++ Standard reads, A program shall contain a global function called main , which is the designated start of the program. Now consider this code, int square(int i) { return i*i; } int user_main() { for ( int i = 0 ; i < 10 ; ++i ) std::cout << square(i) << endl; return 0; } int main_ret= user_main(); int main() { return main_ret; } This sample code does what I intend it to do, i.e printing the square of integers from 0 to 9, before entering into the main() function which is supposed to be the "start" of the program. I also compiled it with -pedantic option, GCC 4

Why does std::cout convert volatile pointers to bool?

我们两清 提交于 2019-11-26 09:04:35
问题 If you try to cout a pointer to a volatile type, even a volatile char pointer where you would normally expect cout to print the string, you will instead simply get \'1\' (assuming the pointer is not null I think). I assume output stream operator<< is template specialized for volatile pointers, but my question is, why? What use case motivates this behavior? Example code: #include <iostream> #include <cstring> int main() { char x[500]; std::strcpy(x, \"Hello world\"); int y; int *z = &y; std: