Data dodania Pytanie
2017-12-09 18:12 Is not matching a template<typename...> to template<typename> a defect? »
While exploring this answer I discovered that a template that takes a parameter pack will not be accepted by a template that expects template that has...
(1) odpowiedzi
2017-12-08 11:12 Understanding overload resolution ranking involving user defined conversion »
I am trying to understand overload resolution. First let's consider this first case: struct int1{ int val; operator int&()&{ ret...
(2) odpowiedzi
2017-12-07 20:12 What made i = i++ + 1; legal in C++17? »
Before you start yelling undefined behaviour, this is explicitly listed in N4659 (C++17) i = i++ + 1; // the value of i is incremented Yet...
(3) odpowiedzi
2017-12-07 10:12 Is std::any_of required to follow short circuit logic? »
Given the following code, std::vector<int> numbers = {1, 2, 3, 4, 5}; std::any_of(std::begin(numbers), std::end(numbers), [](int n...
(1) odpowiedzi
2017-12-06 08:12 When defining a prototype of an overloaded C++ function template, is it legal to use its name to refer to previous definitions? »
Let's say we want to overload a function template f, but only if a similar overload is not declared yet: template<typename T> void f(T); // mai...
(1) odpowiedzi
2017-12-05 15:12 Changed rules for protected constructors in C++17? »
I have this test case: struct A{ protected: A(){} }; struct B: A{}; struct C: A{ C(){} }; struct D: A{ D() = default; }; int main(){ (void)B{}; ...
(2) odpowiedzi
2017-12-03 09:12 What is the rationale for limitations on pointer arithmetic or comparison? »
In C/C++, addition or subtraction on pointer is defined only if the resulting pointer lies within the original pointed complete object. Moreover, comp...
(5) odpowiedzi
2017-12-03 01:12 Anonymous temporaries and class template argument deduction - gcc vs clang »
Consider the following code snippet: template <typename T> struct foo { foo(T) { } }; int main() { foo{0}; } g++ 7 happily creates a...
(1) odpowiedzi
2017-12-02 18:12 Is it legal to check whether the address of a subobject lies within the bounds of a containing object »
2 Questions: Is the following code well formed with defined behaviour? Is there any possible c++ implementation in which it could assert? Code (c+...
(1) odpowiedzi
2017-12-02 14:12 Wrong overload called when constructing from initializer_list inside parentheses »
I always thought that when I use initializer list C++ syntax like: something({ ... }); it's always clear to the compiler that I want to call the ov...
(3) odpowiedzi
2017-12-02 11:12 Can I use the result of a C++17 captureless lambda constexpr conversion operator as a function pointer template non-type argument? »
while answering this question, I tried to turn a captureless lambda into a member function pointer by exploiting the fact that, since C++17, capturele...
(1) odpowiedzi
2017-11-28 19:11 Why does the ternary operator with commas evaluate only one expression in the true case? »
I'm currently learning C++ with the book C++ Primer and one of the exercises in the book is: Explain what the following expression does: someValue...
(5) odpowiedzi
2017-11-27 20:11 What does it mean for `offsetof` to be "conditionally-supported" for non standard-layout classes in C++17? »
The C++17 Standard says: [support.types.layout] Use of the offsetof macro with a type other than a standard-layout class is conditionall...
(1) odpowiedzi
2017-11-24 13:11 Placement new and assignment of class with const member »
Why is that undefined behaviour? struct s { const int id; // <-- const member s(int id): id(id) {} s& operator =(con...
(1) odpowiedzi
2017-11-23 14:11 Typo: bool to int conversion induced error in std::ifstream under Linux »
I had a typo (|| instead of |) and noticed such a code fails with GCC and compiles with Visual. I know that the second parameter of std::ifstream is ...
(1) odpowiedzi
2017-11-22 15:11 Is it undefined behavior to read and compare padding bytes of a POD type? »
Today I've encountered some code that roughly looks like the following snippet. Both valgrind and UndefinedBehaviorSanitizer detected reads of uniniti...
(3) odpowiedzi
2017-11-20 00:11 In C++14, in which scope are unscoped enumerators of redeclared enumerations declared? »
The C++14 (precisely, N4296) says with respect to enumerations, in 7.2:11: Each enum-name and each unscoped enumerator is declared in the scope ...
(0) odpowiedzi
2017-11-18 09:11 Why are C++ classes with virtual functions required to have a non-trivial copy constructor? »
According to the C++ standard, a class that has virtual functions cannot have a trivial copy constructor: A copy/move constructor for class X is t...
(3) odpowiedzi
2017-11-17 16:11 Is it legal to call delete on a null pointer of an incomplete type? »
And if so, why does the following code give me the warning note: neither the destructor nor the class-specific operator delete will be called, eve...
(1) odpowiedzi
2017-11-17 15:11 How can this structure have sizeof == 0? »
There is an old post asking for a construct for which sizeof would return 0. There are some high score answers from high reputation users saying that ...
(4) odpowiedzi
2017-11-14 19:11 How is P0522R0 breaking code? »
Today I was reading the C++17 support page of clang. I've notice something odd. The feature Matching template template parameters to compatible argume...
(1) odpowiedzi
2017-11-13 10:11 Non-dependent name lookup and lambda »
I have the following code: template <class T> class Outer { public: Outer(); template <class U> void templateFunc() { ...
(1) odpowiedzi
2017-11-10 18:11 Is dereferencing invalid pointers legal if no lvalue-to-rvalue conversion occurs »
Try as I might, the closest answer I've seen is this, with two completely opposing answers(!) The question is simple, is this legal? auto p = reinte...
(2) odpowiedzi
2017-11-08 23:11 Is "int (x), 1;" an ambiguous statement? »
void f(int x) { int (x), 1; } Clang compiles it, GCC doesn't. Which compiler is correct? ...
(1) odpowiedzi
2017-11-07 19:11 Is this function pointer with `this` in trailing return type legal? »
class C { auto (*foo)() -> decltype(this); }; This code is accepted by GCC, MSVC, and clang, but not icc. ...
(1) odpowiedzi
2017-11-04 13:11 Call to conversion operator instead of converting constructor in c++17 during overload resolution »
Consider the following two classes : #define PRETTY(x) (std::cout << __PRETTY_FUNCTION__ << " : " << (x) << '\n') struct D; ...
(1) odpowiedzi
2017-11-03 22:11 Does attribute specifier sequence inherit? »
Look at this snippet: struct [[nodiscard]] Result { }; struct DiscardableResult: Result { }; Does DiscardableResult have the [[nodiscard]] attrib...
(1) odpowiedzi
2017-11-02 13:11 Can the compiler optimize from heap to stack allocation? »
As far as compiler optimizations go, is it legal and/or possible to change a heap allocation to a stack allocation? Or would that break the as-if rule...
(3) odpowiedzi
2017-10-30 17:10 Restricting conversion of function pointers »
I wonder why a static_cast from int (*)(const int&) to type int (*)(int&) is illegal. If I have a function pointer that technically allows acc...
(1) odpowiedzi
2017-10-27 11:10 Aggregate initialization does not uphold constructor access »
Given the example here below, I was surprised to find that despite the default constructor explicitly being deleted (or made default for that matter),...
(1) odpowiedzi
2017-10-26 19:10 Is using the result of new char[] or malloc to casted float * is UB (strict aliasing violation)? »
Which code of these has UB (specifically, which violates strict aliasing rule)? void a() { std::vector<char> v(sizeof(float)); float *f...
(3) odpowiedzi
2017-10-25 14:10 Is it allowed to specialize a template with enums with the same integral value? »
Look at this simple snippet: enum class Enum1 { Value }; enum class Enum2 { Value }; template <auto> struct Foo; template <> struct Foo&l...
(1) odpowiedzi
2017-10-24 13:10 Existence of objects created in C functions »
It has been established (see below) placement new is required to create objects int* p = (int*)malloc(sizeof(int)); *p = 42; // illegal, there isn't...
(3) odpowiedzi
2017-10-24 03:10 Is it legal to use a const value captured in a lambda as a template argument? »
Consider the following code, provided by a colleague: #include <array> #include <string> int main() { const int size = 4; return...
(1) odpowiedzi
2017-10-21 20:10 “Default member initializer needed within definition of enclosing class outside of member functions” - is my code ill-formed? »
struct foo { struct bar { ~bar() {} // no error w/o this line }; bar *data = nullptr; // no error w/o this ...
(2) odpowiedzi