language-lawyer

Where in the C++ Standard is the memory layout of objects documented?

拈花ヽ惹草 提交于 2019-12-23 12:55:29
问题 This is a big question, so I'm asking for a reference rather than a booklet-sized answer. I'm going through Stroustrup's Tour of C++, and it seems like the way objects are laid out is memory is fundamental to the design of many C++ features, e.g. PODs vs aggregates vs classes with virtual members. Unfortunately, the Tour itself doesn't cover this subject in detail, and skimming the ToCs of some standard references such as C++ Primer 5ed and TCPPPL 4ed doesn't show whether or where they cover

Is Rust's syntactical grammar context-free or context-sensitive?

家住魔仙堡 提交于 2019-12-23 12:54:51
问题 The syntactical grammar of hardly any programming language is regular, as they allow arbitrarily deeply nested parenthesis. Rust does, too: let x = ((((())))); But is Rust's syntactical grammar at least context-free? If not, what element makes the grammar context-sensitive? Or is the grammar even recursively enumerable, like C++'s syntactical grammar? Related : Is Rust's lexical grammar regular, context-free or context-sensitive? 回答1: Rust includes a macro processor, whose operation is highly

Where in the C++ Standard is the memory layout of objects documented?

风格不统一 提交于 2019-12-23 12:54:40
问题 This is a big question, so I'm asking for a reference rather than a booklet-sized answer. I'm going through Stroustrup's Tour of C++, and it seems like the way objects are laid out is memory is fundamental to the design of many C++ features, e.g. PODs vs aggregates vs classes with virtual members. Unfortunately, the Tour itself doesn't cover this subject in detail, and skimming the ToCs of some standard references such as C++ Primer 5ed and TCPPPL 4ed doesn't show whether or where they cover

Interpretation of [basic.scope.hiding]p2 when unqualified name lookup involves using-directives

大兔子大兔子 提交于 2019-12-23 12:13:26
问题 There are two types of name hiding in c++: 1) Normal name hiding: [basic.scope.hiding]p1 (http://eel.is/c++draft/basic.scope.hiding#1): A name can be hidden by an explicit declaration of that same name in a nested declarative region or derived class ([class.member.lookup]). 2) The special type of name hiding in [basic.scope.hiding]p2 (http://eel.is/c++draft/basic.scope.hiding#2): A class name ([class.name]) or enumeration name ([dcl.enum]) can be hidden by the name of a variable, data member,

Is it valid to pass non-arithmetic types as arguments to cmath functions?

試著忘記壹切 提交于 2019-12-23 11:59:13
问题 Given the following user-defined type S with a conversion function to double : struct S { operator double() { return 1.0;} }; and the following calls to cmath functions using the type S : #include <cmath> void test(S s) { std::sqrt(s); std::log(s); std::isgreater(s,1.0); std::isless(s,1.0); std::isfinite(s) ; } This code compiles with gcc using libstdc++ ( see it live ) but with clang using libc++ it generates errors for several of the calls ( see it live ) with the following error for

Eclipse ECJ accepts this code, javac doesn't - who is right?

 ̄綄美尐妖づ 提交于 2019-12-23 10:09:36
问题 Consider the following returnsNull function and a call to it with a generic type: public static <T> List<T> returnNull(Class<? extends T> clazz) { return null; } public static void main( String[] args ) { List<AtomicReference<?>> l = returnNull(AtomicReference.class); } The Eclipse compiler, when set to Java 8, accepts it, but javac in Java 8 rejects it with: incompatible types: cannot infer type-variable(s) T (argument mismatch; java.lang.Class<java.util.concurrent.atomic.AtomicReference>

Where in the C++ Standard is `a = b + {1, 2}` disallowed in the snippet below? [duplicate]

青春壹個敷衍的年華 提交于 2019-12-23 10:09:29
问题 This question already has an answer here : Initializer lists and RHS of operators (1 answer) Closed 4 years ago . Where in the Standard is a = b + {1, 2} disallowed below? class complex { double re, im; public: complex(double r, double i) : re{ r }, im{ i } {} complex& operator+=(const complex& other) { re += other.re; im += other.im; return *this; } }; inline complex operator+(complex lhs, const complex& rhs) { lhs += rhs; return lhs; } int main() { complex a{ 1, 1 }; complex b{ 2, -3 }; a +

Friending classes defined in the std namespace: any guarantees?

放肆的年华 提交于 2019-12-23 10:04:39
问题 This question came up as I answered this question: does the standard allow and make any guarantees about friend -ing standard library classes and/or functions? In this particular case, the situation the question was whether: class MyUserDefinedType { friend struct std::default_delete<MyUserDefinedType>; private: ~MyUserDefinedType() { } } is guaranteed to allow MyUserDefinedType to be stored in a std::unique_ptr<MyUserDefinedType> or std::shared_ptr<MyUserDefinedType> object with the default

Explicit type conversion (functional notation) with simple-type-specifier

落爺英雄遲暮 提交于 2019-12-23 10:03:04
问题 Porting some code I have discovered that line unsigned char uc = unsigned char(c); is accepted by MSVC but rejected by GCC. Is this syntax correct? Standard says that A simple-type-specifier (7.1.7.2) ... followed by a parenthesized optional expressionlist or by a braced-init-list (the initializer) constructs a value of the specified type given the initializer Does it mean that MS is right? Is unsigned char a 'simple-type-specifier'? 回答1: GCC and CLANG are correct, the code is not valid.

Static table generation works with GCC but not clang; is clang bugged?

大兔子大兔子 提交于 2019-12-23 09:59:46
问题 I wrote some code once upon a time that generated a static table/array at compile time for some template metaprogramming (the idea is that C-style strings can be built at compile time (they're just char arrays)). The idea and the code is based off David Lin's answer: #include <iostream> const int ARRAY_SIZE = 5; template <int N, int I=N-1> class Table : public Table<N, I-1> { public: static const int dummy; }; template <int N> class Table<N, 0> { public: static const int dummy; static int