Questions tagged [language-lawyer]

For questions about the intricacies of formal or authoritative specifications of programming languages.

Typical questions concern gaps between "what will usually work in practice" and "what the spec actually guarantees", but problems with understanding the structure of the spec are also on topic.

Use this tag for questions where you are interested in the formal specification for a certain behavior in the given programming language, even though your question might otherwise have no practical use, or if the code posted would not make sense in a real-world application.

Always combine this tag with a programming language tag.

7856 questions
13
votes
2 answers

Is pandas.DataFrame.groupby Guaranteed To Be Stable?

I've noticed that there are several uses of pd.DataFrame.groupby followed by an apply implicitly assuming that groupby is stable - that is, if a and b are instances of the same group, and pre-grouping, a appeared before b, then a will appear pre b…
Ami Tavory
  • 74,578
  • 11
  • 141
  • 185
13
votes
2 answers

Are super-SCARY iterators legal?

I understand that the standard allows std::vector to have the same type of iterators for different allocators A. This is called SCARY iterators. Now the question is does the standard allow std::vector::iterator be simply a typedef of…
Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
13
votes
1 answer

Is it allowed to use decltype on std::declval (the function itself, not the result of calling it)?

The following code triggers a static assertion on libstdc++: #include using t = decltype(std::declval); Should it? Motivation for this question: The following declval implementation proposed by Eric Niebler (which is…
T.C.
  • 133,968
  • 17
  • 288
  • 421
13
votes
1 answer

Global scope resolution in the presence of using namespace

Consider the following code: namespace foo { namespace bar { class foo {}; } class baz {}; } using namespace foo::bar; ::foo::baz mybaz; Is this code valid? Or is ::foo ambiguous? Or does ::foo refer to the class foo, such that there is…
Zulan
  • 21,896
  • 6
  • 49
  • 109
13
votes
2 answers

Does an else if statement exist?

Some time ago after not standing anymore lines like this: if (arg) invk(test); else if (test) { alot(); stuff(); } I decided for my self its better for readability in our 1920x1200 times, to not omit the {}. So I wrote a tool that…
dhein
  • 6,431
  • 4
  • 42
  • 74
13
votes
2 answers

Is the alignment of char in C (and C++) guaranteed to be 1?

Can the alignof(char) be anything but 1? From the unofficial cppreference.com wiki: The weakest (smallest) alignment is the alignment of the types char, signed char, and unsigned char, and it is usually 1. The "usually" seems to imply that it…
Rufflewind
  • 8,545
  • 2
  • 35
  • 55
13
votes
5 answers

Why does the compiler assume that these seemingly equal pointers differ?

Looks like GCC with some optimization thinks two pointers from different translation units can never be same even if they are actually the same. Code: main.c #include #include int a __attribute__((section("test"))); extern int…
Yuri Syro
  • 549
  • 2
  • 16
13
votes
1 answer

Can I legally use a struct with overloaded operator() as Compare for std::upper_bound?

I have structs like this (types simplified to carry over the point), living in a std::vector: struct Region { int first; int count; struct Metadata region_metadata; }; In the vector, they are ordered by first. If you add first and…
Jonas Schäfer
  • 20,140
  • 5
  • 55
  • 69
13
votes
1 answer

When does it matter that `this` is an rvalue?

I know that the type of this is a prvalue ("pure" rvalue) pointer, and that it may be made a pointer-to-const and/or pointer-to-volatile (affecting accesses to its instance variables), by appending the keywords const or volatile to the end of the…
Theodore Murdock
  • 1,538
  • 1
  • 13
  • 28
13
votes
2 answers

Associativity of fold-expressions

N4191 proposed fold-expressions to C++. The definition there was that (args + ...) is a left-fold (i.e. (((a0 + a1) + a2) + ...), and that (... + args) is a right-fold (i.e. (... + (a8 + (a9 + a10))). However, the revised paper N4295 reversed…
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
13
votes
1 answer

Do the C# and Java specifications spell out the same behavior on signed integer overflow?

In C and C++, the behavior of signed integer overflow or underflow is undefined. In Java and C# (unchecked contexts), the behavior seems to be defined to an extent. From the Java specification, we have: The integer operators do not indicate…
13
votes
1 answer

Incomplete array type int (*p_arr)[ ]?

When I compiled the following code with gcc -Wall -pedantic -ansi -std=c89, it compiled successfully without giving an error at the pointer assignment. Note that I convert from int (*)[4] to int (*)[]. int arr[4]; int (*p_arr)[] = &arr; Assuming…
user1969104
  • 2,340
  • 14
  • 15
13
votes
1 answer

Capturing a Lambda's static in a Nested Lambda

In this answer I use this code: std::vector> imat(3, std::vector(10)); std::for_each(imat.begin(), imat.end(), [&](auto& i) { static auto row = 0; auto column = 0; std::transform(i.begin(), i.end(), i.begin(), …
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
13
votes
1 answer

Casting to void (not pointer) is allowed, why?

Why can I cast this vector to a void (not even a pointer)? int main() { std::vector a; (void)a; } How come this is allowed?
Dean
  • 6,610
  • 6
  • 40
  • 90
1 2 3
99
100