Linked Questions
11 questions linked to/from Are multiple mutations within initializer lists undefined behavior?
2 votes
1 answer
1k views
std::initializer_list and order of evaluation of the elements [duplicate]
Is the comma (,) a sequence point in std::initializer_list? example: is this UB or not: #include <vector> int main() { auto nums = [] { static unsigned x = 2; return ( ...
0 votes
0 answers
124 views
Is a comma in an array initializer a sequence point? [duplicate]
I am not sure if a comma in an array initializer is actually a sequence point. Has the statement below defined behavior? The standard does not discuss side-effects during aggregate initialization ...
303 votes
7 answers
20k views
Can C++ code be valid in both C++03 and C++11 but do different things?
Is it possible for C++ code to conform to both the C++03 standard and the C++11 standard, but do different things depending on under which standard it is being compiled?
17 votes
3 answers
1k views
Incrementing a variable used twice in an initializer list - undefined behavior?
Edit: Not already answered - the linked question was about ordinary r-values, initializer lists are a separate, if related concept. Is this statement well-defined, or is using the prefix increment ...
2 votes
3 answers
2k views
Why is this undefined behaviour?
Here's the sample code: X * makeX(int index) { return new X(index); } struct Tmp { mutable int count; Tmp() : count(0) {} const X ** getX() const { static const X* x[] = { makeX(...
5 votes
2 answers
2k views
Pre-Increment Operators when Using the Variable on the Same Line
I -believe- that what I'm trying to do is probably valid because it is separated in both instances by a comma (not a typical assignment), but I have no idea for sure and search isn't bringing up ...
7 votes
2 answers
417 views
program execution is not started at main()
I developed many years in C and only now discovered that a program can execute code prior to main() function. Here is a code example int generateNum(){ // Some malicious code here... return 5;...
10 votes
1 answer
419 views
Order of evaluation in initializer_list c++11
In the code below is it required that f1 be called before f2 (or vice-versa) or is it unspecified? int f1(); int f2(); std::initializer_list<int> list { f1(), f2() };
5 votes
1 answer
585 views
Are multiple mutations of the same variable within initializer lists undefined behavior pre C++11
Consider the following code: int main() { int count = 0 ; int arrInt[2] = { count++, count++ } ; return 0 ; } If we compile the code using clang -std=c++03 it produces the following ...
0 votes
1 answer
317 views
How to find all objects of class given in variadic template parameters
I want to find all objects of given types and add them to vector. For now I have code: template<class T> void fill1(std::vector<Character*> &vec2) { for (int i = 0; i < ...
2 votes
2 answers
134 views
incorrect output on vector assignment? [duplicate]
Below code snippet is From Herb Sutter's blog here g++ outputs 10. MSVC also does output 10. Output could be different on different compilers. I fail to understand how variable i is incremented. ...