Skip to main content

Questions tagged [language-lawyer]

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

language-lawyer
2 votes
1 answer
91 views

Is comparing two pointers to different char objects undefined in C?

This is code of memmove from https://github.com/gcc-mirror/gcc/blob/master/libgcc/memmove.c void * memmove (void *dest, const void *src, size_t len) { char *d = dest; const char *s = src; if (d &...
k1r1t0's user avatar
  • 735
1 vote
1 answer
69 views

Side effects of constructing an explicitly unused object

Say I have a struct that provides a method that does some work (has useful side effects) and then returns an instance of itself. Do I have to use that instance somehow in order to guarantee that the ...
gstukelj's user avatar
  • 2,471
4 votes
0 answers
63 views

What exception guarantee level does std::vector::operator=() have? [duplicate]

When I assign one std::vector to another std::vector, and std::bad_alloc raises internally, does the C++ specification guarantee that my vector will be left in the correct state? Does it have a basic ...
Andreev Gregory's user avatar
3 votes
1 answer
79 views

Can you call virtual methods on a base class in a union when a derived class is active?

While std::variant is great for some use cases, it's a bit analogous to std::tuple in that you can't name each individual variant. Often a struct is better than a tuple. I'm wondering if it's legal ...
user3188445's user avatar
  • 4,352
2 votes
2 answers
87 views

`static_cast<const bool&>` with `explicit operator bool`

Consider the following: struct C { explicit operator bool() const { return true; } }; int main() { C c; auto b = static_cast<const bool &>(c); return 0; } ...
Nicola Gigante's user avatar
4 votes
1 answer
208 views
+400

Explicit object member function discrepancies between different compilers

I wrote the following program in c++23. Here I've overloaded member functions. But for all cases different compilers give different result as shown below in comment. As you can see I have three cases ...
Alan's user avatar
  • 1,120
0 votes
0 answers
59 views

Is it legal to pass two views to ranges::views::concat such that iterating on the first view will shrink the range backing up the second view?

Here's a small (ok, maybe not minimal) example #include <range/v3/view/concat.hpp> #include <range/v3/view/transform.hpp> #include <unordered_set> #include <vector> #include &...
Enlico's user avatar
  • 26.7k
0 votes
1 answer
68 views

Is GCC correct in rejecting overload between ref-qualified and non-ref-qualified member function? [duplicate]

If I understand this correctly, [over.load] doesn't exist in c++23, and so what I read in [over.load]/2.3 should not be true anymore, so this code struct Foo { int const& bar() const; int bar()...
Enlico's user avatar
  • 26.7k
2 votes
1 answer
98 views

Why are reference types not considered during operator method lookup?

Today I stumbled across the following oddity of Rust's operator/method lookup: use std::ops::Add; use std::fmt::Debug; #[derive(Debug)] struct Foo(i32); impl Add for &Foo{ type Output = ...
ChrisB's user avatar
  • 3,498
47 votes
5 answers
7k views

Can you find a real example of "time travel" caused by undefined behaviour? [closed]

I am curious. Does anyone know a non-hypothetical C or C++ counterexample to the myth that "the impact of the undefined behaviour is limited to code which runs after the line with undefined ...
Andrey Bienkowski's user avatar
13 votes
1 answer
515 views

Why destructor needs to be accessible even when it is not called?

Having class X, the following object initialization: new (ptr) X(X()); requires an accessible destructor even since C++17. Why is that, when the object is initialized by the default constructor ...
Daniel Langr's user avatar
  • 23.1k
1 vote
0 answers
85 views

when unique_ptr implements pimpl, assignment in a class declaration also results in: error: invalid application of 'sizeof' to incomplete type '***'

excuse me, when I was implementing pimpl with std::unique_ptr, I accidentally found that when I set pimpl to nullptr in the header file, gcc(version 9.4.0,14.1.0) cannot be compiled. But cl.exe (...
Bart Simpson's user avatar
2 votes
1 answer
159 views

Explicit this member function use accepted by msvc but rejected by clang and gcc

I wrote the following program that compiles with msvc but rejected by clang and gcc. It uses explicit object member function. Demo. #include <iostream> struct C{ int f(this int); }; ...
Alan's user avatar
  • 1,120
1 vote
2 answers
60 views

get constexpr variable from a lambda function is fine , but compile fail (Visual C++) and fine (gcc) when such statement is in a new lambda

This code compiles fine in gcc, but fail in Visual C++. MCVE = https://wandbox.org/permlink/SqNI85EospSrwm5T int main() { auto func_do1Pass2=[&]() { return 8; }; constexpr int ...
cppBeginner's user avatar
  • 1,116
1 vote
1 answer
19 views

UML: Stereotypes of the Standard Profile

In the UML 2.5.1 specification under section 22 "Standard Profile", p. 721 of the PDF file, it says: "The Standard Profile specifies a set of predefined standard stereotypes. A ...
Robert Hairgrove's user avatar

15 30 50 per page
1
2 3 4 5
560