Menu
  • HOME
  • TAGS

Issue with std::reference_wrapper

c++,c++11,language-lawyer,implicit-conversion,reference-wrapper

The issue is that the non-member operator< for std::vector is a function template: template< class T, class Alloc > bool operator<( const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs ); Implicit conversions are not considered when doing template type deduction here, [temp.arg.explicit] emphasis on if: Implicit conversions (Clause 4) will be performed...

Function returning another function

c++,declaration,language-lawyer

I've read the section 8.3.5 of the current C++ standard Obviously not very carefully. §8.3.5 [dcl.fct]/p8: Functions shall not have a return type of type array or function, although they may have a return type of type pointer or reference to such things. ...

static_assert dependent on non-type template parameter (different behavior on gcc and clang)

c++,templates,language-lawyer,c++14,dependent-name

Quotes found by @TartainLlama If a hypothetical instantiation of a template immediately following its definition would be ill-formed due to a construct that does not depend on a template parameter, the program is ill-formed; no diagnostic is required. N4296 [temp.res]/8 This applies immediately after the primary template is defined (the...

Template overload resolution for operators inside an anonymous namespace

c++,templates,gcc,language-lawyer,argument-dependent-lookup

This is definitely a bug in gcc. The code below rightly prints right with clang but wrong with GCC. #include <iostream> template<typename T> struct A{ T t; }; struct B{}; struct C : public B{}; std::ostream& operator<< (std::ostream& out, const B&) { return out << "right"; } namespace { template<typename...

Must the C++ standard library support classes that are picky about who their friends are?

c++,stl,language-lawyer,friend,access-modifiers

std::copy requires an output iterator ([algorithms.general]/p5); output iterators, among other things, require *r = o to be valid ([output.iterators], Table 108) - not just "valid sometimes" or "valid in some contexts". Since for Picky *p, a;, *p = a isn't valid in most contexts, Picky * isn't a valid output...

Using `reinterpret_cast` on an enum class - valid or undefined behavior?

c++,language-lawyer,c++14,reinterpret-cast,enum-class

The standard is a bit unclear: 3.10 Lvalues and rvalues [basic.lval] 10 If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined: [...] (10.4) -- a type that is the signed or unsigned...

Memory location of bit-fields

c++,language-lawyer,bit-fields

No, they do not share any bit as they would in the union example. They just are considered one unit for the purposes of considering memory locations. Put another way, the following would be the bits in your example (potentially) AAAAAAAA BBBBBCCCCCCCCCCC DDDDDDDD EEEEEEEE (ee sharing e) The spaces are...

Why do iterators need to be default-constructible

c++,stl,iterator,language-lawyer,standard-library

Forward iterators and stronger are required to refer to some external sequence (see [forward.iterators]/6 which says "If a and b are both dereferenceable, then a == b if and only if *a and *b are bound to the same object.") This means they are generally just a lightweight handle onto...

Does C language specify any implicit initialization for void pointers only?

c,pointers,initialization,language-lawyer,void-pointers

I think, the C11 standard is quite clear in this regard. Referring chapter 6.7.9, paragraph 10, If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate. Now, an indeterminate value is , well, indeterminate (which you're referring to as garbage and / or NULL...

Why is repeated inheritance / duplicate inheritance invalid?

c++,inheritance,multiple-inheritance,language-lawyer

Why isn't this supported by C++ ? The reason why your compiler doesn't accept this kind of multiple inheritance, is because it's explicitely forbidden in the C++ standard: Section 10.1 point 3: A class shall not be specified as a direct base class of a derived class more than once....

Why is this configurable property not deletable?

javascript,properties,language-lawyer,ecma262

Effectively, configurable properties are deletable. But there is a big problem: that only applies to native objects, but not to host objects. As explained in 8.6.2 - Object Internal Properties and Methods, Host objects may support these internal properties with any implementation-dependent behaviour as long as it is consistent with...

How is friendship conferred for a class defined within a friend function?

c++,language-lawyer

This is the very first paragraph of the standard section on local classes: A class can be declared within a function definition; such a class is called a local class. The name of a local class is local to its enclosing scope. The local class is in the scope of...

Does the following chained assignment cause Undefined behavior?

c,variable-assignment,language-lawyer,undefined-behavior

IMHO, a = b = a+1 is well-defined. Here. you're not changing the value of a, just using it, in case of a+1. To be explicit, according to the "right-to-left" associativity of = operator, you can break down the above as, b = a + 1; //a does not change...

Weird overload resolution with variadic function templates

c++,c++11,language-lawyer,variadic-templates,overload-resolution

Within the variadic function template f(), the f in the recursive call is a dependent name due to [temp.dep], emphasis mine: In an expression of the form: postfix-expression ( expression-listopt) where the postfix-expression is an unqualified-id, the unqualified-id denotes a dependent name if (1.1) — any of the expressions in...

Reference as a non-type template argument

c++,c++11,language-lawyer

Introduction It is correct saying that the name of a reference is an id-expression, though; the id-expression doesn't refer to whatever the reference is referencing, but the reference itself. int a = 0; int& ref = a; // "ref" is an id-expression, referring to `ref` - not `a` The Standard...

In C++, What does “access” mean in the strict aliasing rule?

c++,language-lawyer,strict-aliasing

It must mean both read and write, or the rule wouldn't mean much. Consider the example from http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html: float *P; void zero_array() { int i; for (i = 0; i < 10000; ++i) P[i] = 0.0f; } The example code above can be optimized into a memset only if the...

Ambiguity in the standard on undefined behaviour of out of range pointer

c++,c++11,language-lawyer,semantics,undefined-behavior

The paragraph you're quoting refers to pointer arithmetic, not to evaluation of pointers. It states that the only time pointer addition p + i is defined is if (treating subtraction of i as equivalent to addition of -i) p points to an element of an array object or one past...

Are unsigned integer types always of different sizes?

c,language-lawyer

In general, yes, this is absolutely possible. For the specific case of the uintN_t types defined in <stdint.h>, as you noted (C11 §7.20.1.1): The typedef name uintN_t designates an unsigned integer type with width N and no padding bits. Thus, uint24_t denotes such an unsigned integer type with a width...

Can we perform deleting object through a pointer to one of its base classes? [duplicate]

c++,language-lawyer,undefined-behavior

"Does it cause UB if we define a virtual destructor?" No that's just fine as the destructor was declared virtual. Stepping up the vtable and calling ~B first will be handled by delete. ...

Why is the value of a pointer-to-member always the same for different members of the same struct?

c++,language-lawyer,pointer-to-member

There's no overload for << to format the value of a member pointer, so you won't get anything particularly useful if you try. There is an overload for bool, and member pointers are convertible to bool, so that is what happens here. The pointer isn't null, so it converts to...

Can headers always be combined?

http,http-headers,language-lawyer

In theory, yes, see http://greenbytes.de/tech/webdav/rfc7230.html#field.order. (and note the exception for Set-Cookie)...

Is modifying the pointed value and the pointer at the same time UB

c++,c,language-lawyer,undefined-behavior

The reason both *i = *i++ + *j++; and *i++ = *i + *j++; are undefined is that you are attempting to use the pointer i in an expression that's a value computation (dereference, *i) and an expression with a side effect (dereference and increment, *i++) without an intervening sequence...

non-static data member initialization with new expression

c++,c++11,gcc,language-lawyer

This is another example of the problem described in Core issue 325 (see the "Notes from the August, 2011 meeting" which have a very similar example), namely that the comma in the template argument list causes a parse failure when the compiler tries to determine where the end of the...

Contradictory results between GCC and clang related to [basic.link]/7 in the C++ Standard

c++,c++11,language-lawyer,c++14,linkage

[basic.link]/p7, emphasis mine: When a block scope declaration of an entity with linkage is not found to refer to some other declaration, then that entity is a member of the innermost enclosing namespace. However such a declaration does not introduce the member name in its namespace scope. [namespace.memdef]/p2, emphasis mine:...

Where in the Standard does it say that a member alias-declaration can be used as if it was a static member?

c++,alias,language-lawyer,c++14

This is just your normal qualified lookup. From [basic.lookup.qual]: The name of a class or namespace member or enumerator can be referred to after the :: scope resolution operator (5.1) applied to a nested-name-specifier that denotes its class, namespace, or enumeration. Then from [class.qual]: If the nested-name-specifier of a qualified-id...

Ambiguous name lookup with using-directive

c++,language-lawyer,name-lookup,qualified-name

The code is ill-formed. When looking up A, §7.3.4/6 steps in: If name lookup finds a declaration for a name in two different namespaces, and the declarations do not declare the same entity and do not declare functions, the use of the name is ill-formed. Here, the namespaces are the...

Where in the C++ Standard the lookup for an unqualified *mem-initializer-id* is defined?

c++,language-lawyer

It is 3.4.1/8. What you have probably missed is that the mem-initializer-list is part of the function body for the constructor. See the grammar production for function-body: function-body: ctor-initializeropt compound-statement function-try-block = default ; = delete ; It then follows from 3.3.7/1 that this is in the potential scope of...

Why char is of 1 byte in C lanaguage

java,c,char,language-lawyer

char is 1 byte in C because it is specified so in standards. The most probable logic is. the (binary) representation of a char (in standard character set) can fit into 1 byte. At the time of the primary development of C, the most commonly available standards were ASCII and...

Compilation issue with instantiating function template

c++,c++11,language-lawyer,variadic-templates,function-templates

Your code is ill-formed. mem_fn is in a non-deduced context according to [temp.deduct.type]: The non-deduced contexts are: — ... — A function parameter pack that does not occur at the end of the parameter-declaration-list. And from [temp.param]: A template parameter pack of a function template shall not be followed by...

Why is implicit pointer of pointer to pointer conversion legal?

c,pointers,language-lawyer

The conversion is not legal. More precisely, there is no implicit conversion from int* to int**, or from int*** to int**. Attempting to pass an int* or an int*** to a function that requires an int** argument is a constraint violation; any conforming compiler must diagnose it. (The diagnostic message...

clang bug? namespaced template class' friend

c++,g++,language-lawyer,clang++

I believe that clang is correct. According to [namespace.memdef]/3: Every name first declared in a namespace is a member of that namespace. If a friend declaration in a non-local class first declares a class, function, class template or function template the friend is a member of the innermost enclosing namespace....

Issue warning and compiling with warnings-as-errors violates compliance?

c++,language-lawyer

Yes, if you tell the implementation not to conform with the standard (for example, by requesting errors for well-formed code constructs), then its behaviour won't be conforming.

Does upcasting a null pointer lead to undefined behavior

c++,language-lawyer,implicit-conversion,nullptr,up-casting

Stroustrup discusses this case in section 4.5 of his 1989 multiple inheritance paper [PDF]: The solution is to elaborate the conversion (casting) operation to test for the pointer-value 0 [...] The added complexity and run-time overhead are a test and an increment. The implementation checks explicitly for null-values and ensures...

Initialize data members of class in C++ 11

c++,initialization,language-lawyer

Early proposals leading to the feature's introduction explain that this is to avoid parsing problems. Here's just one of the examples presented therein: Unfortunately, this makes initializers of the “( expression-list )” form ambiguous at the time that the declaration is being parsed: struct S { int i(x); // data...

Why does clang's stdbool.h contain #define false false

c++,clang,language-lawyer

stdbool.h is a C header, not a C++ header. It is not usually found in C++ programs because true and false are already keywords in C++. Consequently, if a C++ program includes stdbool.h it is a fairly clear indication that it is a ported-over C program (e.g. a C program...

Do parentheses make a difference when determining the size of an array?

c,arrays,language-lawyer,sizeof,parentheses

Whether seemingly redundant parentheses affect the semantics of a program is a long-standing issue in the C standard that still hasn't been adequately resolved. It is commonly claimed that ((void*)0) is technically not a null pointer constant, because there is no rule that says a parenthesised null pointer constant is...

Safety of static_cast to pointer-to-derived class from base destructor

c++,casting,language-lawyer,static-cast

[expr.static.cast]/p11: A prvalue of type “pointer to cv1 B,” where B is a class type, can be converted to a prvalue of type “pointer to cv2 D,” where D is a class derived (Clause 10) from B, if a valid standard conversion from “pointer to D” to “pointer to B”...

constexpr char array with GCC and clang

c++,arrays,c++11,language-lawyer,constexpr

It's a bug and appears to compile on gcc 5 as shown here.

May iterator's operator * return by-value?

c++,language-lawyer

Forward and stronger iterators are supposed to have reference be an actual reference type ([forward.iterators]/p1): A class or pointer type X satisfies the requirements of a forward iterator if [...] if X is a mutable iterator, reference is a reference to T; if X is a const iterator, reference is...

.net decimal - remove scale, solution that is guaranteed to work

c#,decimal,language-lawyer

You pretty much answered your question yourself. Personally, I would not obsess so much about which method to use. If you method works now - even if it is undocumented - then it will most likely work in the future. And if a future update to .NET breaks your method...

C++ Templates with pointer to member function by signature and type

c++,templates,pointers,function-pointers,language-lawyer

Best go through this one by one. To avoid ambiguities, I'll use different template argument names in the example template<class C, class signature> void f(signature C::*ptr) {} All quotes refer to the latest working draft of the C++14 standard. First we need to understand, how the template parameters are treated....

Is it definitely illegal to refer to a reserved name?

c++,c++11,language-lawyer,c++14

Whether it's legal or not is implementation-specific (and identifier-specific). When the Standard gives the implementation the sole right to use these names, that includes the right to make the names available in user code. If an implementation does so, great. But if an implementation doesn't expressly give you the right,...

MSVC 12 std::initializer_list bug when copying std::string

c++11,visual-studio-2013,language-lawyer,msvc12

The problem is that you're using both parentheses and braces: std::initializer_list<TestStructure> structures({structure}); ^^ ^^ This will construct a temporary std::initializer_list<TestStructure> and copy it to structures; the normal lifetime-extension will not be performed, so structures will be pointing to destructed storage: [dcl.init.list]: 6 - The array has the same lifetime as...

Is this code standard compliant or not?

c++,c++11,language-lawyer,c++14,c++98

Your program does induce UB. §9.3.1/2: If a non-static member function of a class X is called for an object that is not of type X, or of a type derived from X, the behavior is undefined. A is not of type B or a type derived from B....

Can addresses of unmodified locals wind up corrupted in setjmp/longjmp?

c,clang,language-lawyer,longjmp,address-sanitizer

Is there a reason the helper call is "embedded" into the controlling expression of if through ?: operator? This is actually a violation of the language requirements that says 7.13.1.1 The setjmp macro 4 An invocation of the setjmp macro shall appear only in one of the following contexts: —...

Is following statement valid in ANSI C? Is it valid at all?

c,language-lawyer,c89,sequence-points

Both are valid statements, i.e. legal C, and in both cases, the behavior is undefined.

Why does ISO C forbid casting nonscalar to the same type

c,language-lawyer

The warning message is a bit misleading. ISO C doesn't just forbid casting a nonscalar to the same type; it forbids casting a nonscalar to or from any type. Both the operand of a cast operator, and the type specified in the cast itself, must be of scalar type (either...

Trying to understand [basic.def.odr]/2 in C++14 (N4140)

c++,language-lawyer,c++14

I'm using a recent github draft based on N4296. The actual C++14 International Standard does not contain this example, nor the numbering of bullet points. The specification relevant here is effectively the same. We decompose the expression in the initializer: b ? (1, S::x) : f(S::x) The expression (1, S::x)...

Is typename required or not here?

c++,templates,c++11,language-lawyer,typename

[class.inhctor]/p1, emphasis mine: A using-declaration (7.3.3) that names a constructor implicitly declares a set of inheriting constructors. A constructor is not a type. [temp.res]/p3-4: 3 When a qualified-id is intended to refer to a type that is not a member of the current instantiation (14.6.2.1) and its nested-name-specifier refers to...

What does a compiler check for uninstantiated template code?

c++,templates,gcc,clang,language-lawyer

The standard only requires the name-lookup to happen at phase 1, when the template is first parsed. This turns up badfoo in badbar which is why the code compiles. The compiler is not required to do the overload resolution at that time. The overload resolution (which always happens as a...

Why does the Java 8 generic type inference pick this overload?

java,generics,java-8,language-lawyer

The rules of type inference have received a significant overhaul in Java 8; most notably target type inference has been much improved. So, whereas before Java 8 the method argument site did not receive any inference, defaulting to Object, in Java 8 the most specific applicable type is inferred, in...

Does MISRA C 2012 say not to use bool

language-lawyer,c99,misra,pc-lint

Use of modifier or type '_Bool' outside of a typedef [MISRA 2012 Directive 4.6, advisory] That's nonsense, directive 4.6 is only concerned about using the types in stdint.h rather than int, short etc. The directive is about the basic numerical types. bool has nothing to do with that directive...

Is it legal to call memcpy with zero length on a pointer just past the end of an array?

c,pointers,language-lawyer,undefined-behavior

3.15 object object region of data storage in the execution environment, the contents of which can represent values The memory, pointer to one past the last element points to, of an array object or an object cannot represent values, since it cannot be dereferenced ( 6.5.6 Additive operators, paragraph...

Reading uninitialized variable

c++,language-lawyer

Here is the relevant section, I think: 4.1 Lvalue-to-rvalue conversion 1 - A glvalue of a non-function, non-array type T can be converted to a prvalue. If T is an incomplete type, a program that necessitates this conversion is ill-formed. If the object to which the glvalue refers is not...

Does the C# compiler get the Color Color rule wrong with const type members?

c#,language-lawyer,member-access

It is a bug. I am unable to reproduce the problem in CTP 5 of VS 2015, and I think this one should have been fixed as part of the Roslyn rewrite. However, a commenter below notes that they can reproduce it in CTP 6. So I'm not sure what...

Is round-trip through floating point always defined behavior if floating point range is bigger?

c++,language-lawyer,c++14,floating-point-conversion

No. It's possible that i == std::numeric_limits<I>::max(), but that i is not exactly representable in F. If the value being converted is in the range of values that can be represented but the value cannot be represented exactly, it is an implementation-defined choice of either the next lower or higher...

C operator += Sequence point?

c,pointers,language-lawyer,undefined-behavior,sequence-points

It is undefined behavior because the evaulation of *p is unsequenced in related to the evaluation of *p--. There is no sequence point. For all assignment operators, 6.5.16: The side effect of updating the stored value of the left operand is sequenced after the value computations of the left and...

AFAIK, the code below shouldn't compile, but it does in clang and GCC. What am I missing here?

c++,c++11,language-lawyer

The bullet is X is a union-like class that has a variant member with a non-trivial default constructor which is parsed as X is a union-like class that has (a variant member with a non-trivial default constructor) i.e., "with a non-trivial default constructor" applies to the type of the variant...

Is it legal to read data out of a function pointer?

c,language-lawyer

From C standards perspective, no, it's not. Annex J in N1570 has a chapter on common extensions: J.5 Common extensions The following extensions are widely used in many systems, but are not portable to all implementations. The inclusion of any extension that may cause a strictly conforming program to become...

Making a private inherited inner template public via a using directive

c++,templates,c++11,language-lawyer

Not possible. A using-declaration is, from [namespace.udecl]: using typenameopt nested-name-specifier unqualified-id ; But an unqualified-id can't be a class template. You could just make an alias instead: template<typename T> class Derived: private Base<T> { public: template <typename U> using Inner = typename Base<T>::template Inner<U>; Inner<T>* ptr; }; ...

is return main(); a valid syntax?

c,function,return,language-lawyer,return-type

I didn't know that the return statement accepts any parameter that can be evaluated to the expected return data type, Well, a return statement can have an expression. Quoting C11 standard, chapter 6.8.6.4, The return statement. If a return statement with an expression is executed, the value of the...

Explicit call to destructor of template parameter type, even when instantiated on a builtin

c++,language-lawyer

This is indeed valid C++ (and has been since C++98, as far as I know), and known as a pseudo-destructor call. N4431 §5.2.4 [expr.pseudo]: 1 The use of a pseudo-destructor-name after a dot . or arrow -> operator represents the destructor for the non-class type denoted by type-name or decltype-specifier....

Do floats, doubles, and long doubles have a guaranteed minimum precision?

c++,floating-point,language-lawyer,floating-point-precision,minimum

If std::numeric_limits<F>::is_iec559 is true, then the guarantees of the IEEE 754 standard apply to floating point type F. Otherwise (and anyway), minimum permitted values of symbols such as DBL_DIG are specified by the C standard, which, undisputably for the library, “is incorporated into [the C++] International Standard by reference”, as...

What is included in C Standard library?

c,linux,posix,standards,language-lawyer

As far as I can see, in C11 standard, there is no unistd.h and fcntl.h. So, strictly speaking, they are not part of the C standard. When it comes to the implementation part, the GNU C library (glibc) is one of them. From the wiki page glibc provides the functionality...

Integer promotion for implementations where sizeof(short) == sizeof(int)

c++,language-lawyer

It is perfectly legitimate, and at one time was extremely commonplace, for short and int to have identical ranges and representations; even in today it's not uncommon for embedded systems to use the same 16-bit representation for both. The C specification does contain some language which is specific to such...

std::vector::resize(size_type) requires CopyInsertable?

c++,c++11,language-lawyer

You are correct. It was a defect in C++11 that was fixed for C++14 by http://cplusplus.github.io/LWG/lwg-defects.html#2033 The current wording says: Effects: If sz < size(), erases the last size() - sz elements from the sequence. Otherwise, appends sz - size() default-inserted elements to the sequence. Requires: T shall be MoveInsertable...

Is it safe to use operator [] for std::string

c++,language-lawyer

Yes, it's safe, at least explicitly from C++11. From [string.require], emphasis mine: The char-like objects in a basic_string object shall be stored contiguously. That is, for any basic_string object s, the identity &*(s.begin() + n) == &*s.begin() + n shall hold for all values of n such that 0 <=...

Why can't I complete the type with the typedef?

c++,language-lawyer

Incomplete is a type, introduced by your declaration and you cannot have a typedef using the same name, refering to another type. Your struct Incomplete; is a forward class declaration which inserts a class-name into the global scope (and introduces a new, yet incomplete type). §9/2 A class-name is inserted...

The destructor for the class member `B`, why is it invoked in the snippet below?

c++,language-lawyer,c++14,delete-operator

Your delete *a applies operator delete to a non-pointer expression *a of type A. The only way this can be legal is when type A is implicitly convertible to some pointer type. 5.3.5 Delete [expr.delete] 1 ... The operand shall have a pointer to object type, or a class type...

GCC rejects a simple-declaration with an enum-base; clang accepts it — which is correct?

c++,c++11,enums,language-lawyer,c++14

Your reasoning is correct. An enum-base like ": int" is syntactically allowed only in an enum-specifier, which must contain a { bracketed } list of enumerators, or in an opaque-enum-declaration, which must follow the enum-base with an immediate semicolon ;.

Does it violate the standard for a non-default-constuctible struct to lack a user-defined constructor?

c++,visual-studio-2012,language-lawyer,default-constructor,aggregate-initialization

The standard explicitly allows cases like Foo in [12.1p4]: [...] If there is no user-declared constructor for class X, a constructor having no parameters is implicitly declared as defaulted [...] A defaulted default constructor for class X is defined as deleted if: [...] any potentially constructed subobject, except for a...

Do C and C++ standards imply that a special value in the address space must exist solely to represent the value of null pointers?

c++,c,language-lawyer,systems-programming

does it imply that these languages require that a special value in the address space is dead, meaning that it's unusable except for the role of representing nullptr? No. The compiler needs a special value to represent a null pointer, and must take care that it does not place...

C++11 introduced exception constructors taking `const char*`. But why?

c++,exception,c++11,language-lawyer

This allows (or at least is apparently intended to facilitate--see more below) the implementation to eliminate copies in cases where it can detect (by means that are not themselves standardized) that what's being passed is a string literal or something else with static storage duration. Just for example, let's assume...

Can't understand the declaration #3 in the Example of [basic.link]/6 C++14

c++,declaration,language-lawyer,c++14,extern

This is subject to active issue 426 which says: An example in 3.5 [basic.link] paragraph 6 creates two file-scope variables with the same name, one with internal linkage and one with external. static void f(); static int i = 0; //1 void g() { extern void f(); // internal linkage...

does enum fields have default values in c language

c,enums,initialization,language-lawyer

Yes, it does. As per C11 standard, chapter §6.7.2.2, Enumeration specifiers, paragraph 3, (emphasis mine) The identifiers in an enumerator list are declared as constants that have type int and may appear wherever such are permitted.127) An enumerator with = defines its enumeration constant as the value of the constant...

Why are the UINTX_C() macros not properly defined in Windows stdint.h?

c++,macros,windows-7-x64,language-lawyer

As far as I can tell, the are defined correctly. The macros expand to integer constant expressions corresponding to the specified types, not of the specified types. Neither C nor C++ has a syntax for integer constant expressions of types narrower than int. It depends on implicit conversions to convert...

C++14 warning: too many template headers for variable (should be 0)

c++,language-lawyer,c++14,template-specialization,variable-templates

Template arguments can only be omitted in explicit specialisation of function templates. You have a variable template, so you have to include the <int>: template<> int a<int> = 1; Quoting C++14 (n4140), 14.7.3/10 (emphasis mine): A trailing template-argument can be left unspecified in the template-id naming an explicit function template...

Does not evaluating the expression to which sizeof is applied make it legal to dereference a null or invalid pointer inside sizeof in C++?

c++,language-lawyer,sizeof,undefined-behavior,null-pointer

I believe this is currently underspecified in the standard, like many issues such as What is the value category of the operands of C++ operators when unspecified?. I don't think it was intentional, like hvd points outs it is probably obvious to the committee. In this specific case I think...

C11 & C++11 Exended and Universal Character Escaping

c++,c++11,language-lawyer,c11,ucn

'é' is not a valid character to backslash escape in a string literal, and so a backslash followed by 'é' as either a literal source character or a UCN should produce a compiler diagnostic and undefined behavior. Note, however, that "\\u00e9" is not a UCN preceded by a backslash, and...

Declaring friend class template via wrapper

c++,templates,language-lawyer,friend

§7.1.6.3/2: If the identifier resolves to a typedef-name or the simple-template-id resolves to an alias template specialization, the elaborated-type-specifier is ill-formed. ...

Function signature returning abstract class

c++,abstract-class,language-lawyer,signature

Is this code standard-compliant? No. According to C++11 [class.abstract]/3, "An abstract class shall not be used as a parameter type, as a function return type, or as the type of an explicit conversion." If not, what is the reasoning behind forbidding declaring such signature type? A function of that...

I don't understand how the template function gets to be a friend of the class A::X::Y in the example in [namespace.memdef]/3 in C++14

c++,templates,language-lawyer,c++14,friend

It doesn't have to be in namespace A. I think the confusion might come from this sentence from [namespace.memdef]/3: If the name in a friend declaration is neither qualified nor a template-id and the declaration is a function or an elaborated-type-specifier, the lookup to determine whether the entity has been...

Const vs. array-to-pointer conversions

c++,arrays,type-conversion,const,language-lawyer

This is correct: the parameter type of fa is const char *, not char * const. This a subtlety of the meaning of an array declaration, and the adjustment of an array type to a pointer type as a function argument. First the array type itself is adjusted: C++11 8.3.4/1:...

Adjacent character and string literal tokens

c,string,char,language-lawyer,c11

No, maybe we're getting a wrong meaning out of the statement made there. Let me quote from C11, chapter §5.1.1.2, Translation phases, paragraph 6, Adjacent string literal tokens are concatenated. Here, we don't have any confusion between char and string literals, it's clearly mentioned about string literals only....

What does 'transmitted' mean in printf function return?

c,language-lawyer

The word "transmitted" implies that the bytes cross some interface. I submit that the interface that 7.19.6.3 refers to is the interface between printf and the device driver, whereas the interface that 7.19.3 refers to is the output of the device driver. Furthermore, I submit that the interpretation you propose...

Scope and Default Arguments in Template Declarations in C++ : Clarifying Standardese

c++,templates,language-lawyer,c++14

I'm not sure I can follow your thoughts fully, but I think the standard simply uses overly clear wording. It is probably meant to clarify that the "same" template in a different scope may have different default parameters. Example: namespace A { template< int = 42 > struct X; }...

What is a trivial function?

c++,language-lawyer,c++14

"non-trivial function" is the complement of "trivial special member function". There are definitions for what a trivial and non-trivial default/copy/move constructor, copy/move assignment operator or destructor is - traits that only appertain to special member functions, and decide whether e.g. these need to be called under certain circumstances. The definitions...

Can constexpr be combined with volatile?

c++,c++11,gcc,clang,language-lawyer

Yes, this is valid, there was defect report 1688: Volatile constexpr variables that was filed for this, saying: There does not appear to be language in the current wording stating that constexpr cannot be applied to a variable of volatile-qualified type. Also, the wording in 5.19 [expr.const] paragraph 2 referring...

Is it legal to for a function declared “inline” to be recursive?

c,recursion,segmentation-fault,inline,language-lawyer

Quoting the standard: (§6.7.4 Function Specifiers, para. 6) A function declared with an inline function specifier is an inline function. Making a function an inline function suggests that calls to the function be as fast as possible. The extent to which such suggestions are effective is implementation-defined. Oddly, nothing in...

Can an implementation specify undefined behavior

c,standards,language-lawyer,undefined-behavior,c11

No, semantically this is not possible. Undefined behavior is what the term states, behavior that is not defined by the standard. If the standard requests implementation defined behavior, it explicitly request the implementation to specify what it does when a certain error occurs. undefined behavior behavior, upon use of a...

Is there any reason for §3.3.7/1.2 to be considered an error?

c++,language-lawyer

The problem is that in member function scope (and other class scopes) the class version of the enum shadows the global value. If it wasn't an error, the compiler would have to pick one of two surprising behaviors: 1) Use the class enum's value always, which means it would have...

Can an implementation consider hints as actual statements?

c,embedded,language-lawyer

As you say, the standard says "The extent to which such suggestions are effective is implementation-defined." That gives the implementation free range to do anything from ignoring the suggestion to moving heaven and earth to implement it. An implementation which chooses to accept the register specifier as requiring the use...

C++: Is the ignored return value destruction behavior well-defined

c++,language-lawyer

The returned temporary is destroyed immediately after the full expression completes except if its lifetime is extended by being bound to an rvalue or const lvalue reference.

Does deleting a copy constructor or copy assignment operator count as “user declared”?

c++11,move,language-lawyer,copy-constructor

According to slide 14 of your presentation, a deleted copy constructor is "user declared" thus inhibiting the move generation.

Does reinterpret_casting an integral to a pointer type and back yield the same value?

c++,pointers,language-lawyer,integral,reinterpret-cast

No, that is not guaranteed by the standard. Quoting all parts of C++14 (n4140) [expr.reinterpret.cast] which concern pointer–integer conversions, emphasis mine: 4 A pointer can be explicitly converted to any integral type large enough to hold it. The mapping function is implementation-defined. [ Note: It is intended to be unsurprising...

Do C# and Java longs form a commutative ring?

java,c#,language-lawyer,integer-overflow

On platforms were signed values that overflow are defined as wrapping, signed and unsigned values will behave in isomorphic fashion when fed to the +, -, *, &, ^, |, <<, and ~ operators, or when performing an unchecked cast to a smaller type. They will behave differently when used...