Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
3 votes
1 answer
100 views

std::variant::operator< unexpected call to implicit bool conversion. Varies between standards

I'm seeing some unexpected behavior when using the std::variant::operator<. In the situation where the type has an implicit bool conversion operator and its less operator is not a member function (...
Plog's user avatar
  • 9,492
2 votes
0 answers
39 views

Is the initialization of an object a modification to a memory location when considering conflict actions?

struct A{int a; A():a(1){}} std::atomic<A*> x; // thread 1: A* ptr = new A(); // #1 x.store(ptr,memory_order​::​relaxed); //thread 2: auto ptr = x.load(memory_order​::​relaxed); int b = ptr-&...
xmh0511's user avatar
  • 7,280
1 vote
1 answer
84 views

consteval member function allowed?

I have this c++20/23 code: #include <cstddef> template <size_t N> class Foo { public: consteval size_t size() noexcept { return N; } size_t real_size() { ...
HCSF's user avatar
  • 2,587
2 votes
1 answer
72 views

Order of c++ template arguments affecting compilation

I just encountered a new compilation error in my code after a visual studio update. I have stripped my code down to what I think is a minimal example. I have two templated functions both called pow - ...
Phil Rosenberg's user avatar
6 votes
2 answers
150 views

In C++26, are implementations required to "initialize" uninitialized variables to some fixed byte pattern?

In C++26, reading uninitialized variables is no longer undefined, it's "erroneous" now (What is erroneous behavior? How is it different from undefined behavior?). However, the wording for ...
HolyBlackCat's user avatar
  • 91.2k
2 votes
1 answer
63 views

Is `AcqRel` necessary in the atomic read-modify-write operation to avoid data race in a lock-free multi-producer single consumer queue?

Consider this snippet code of implementing a lock-free multi-producer single-consumer queue in Rust struct Node<T> { next: AtomicPtr<Node<T>>, value: Option<T>, } impl&...
xmh0511's user avatar
  • 7,280
4 votes
2 answers
110 views

Move elision in explicit object member functions

If one calls explicit object member function of a temporary, must the move of the temporary be elided in the explicit object parameter? Consider the following example, where struct A has move ...
Fedor's user avatar
  • 19.3k
-1 votes
1 answer
49 views

tool do determine the value category an expression: understanding the result when using references

Looking into definition of value-categories, I tried a snippet proposed here: https://stackoverflow.com/a/16638081/21691539 template <typename T> struct value_category { // Or can be an ...
Oersted's user avatar
  • 1,708
4 votes
1 answer
83 views

Can I use template parameters to refer to base class member functions?

I'm trying to understand why this code doesn't compile with GCC but compiles with MSVC: template<class TParams> class Selector : public TParams::DataSource1, public TParams::DataSource2 { ...
Osyotr's user avatar
  • 1,078
2 votes
1 answer
95 views

Overload resolution between ordinary and explicit object member functions

In the following test program, struct B has two member functions f, which can be called using B{}.f(): one ordinary f() and another with explicit object f(this A). struct A { int f() { return 1; } ...
Fedor's user avatar
  • 19.3k
5 votes
1 answer
99 views

On which member is no_unique_address needed and why?

Consider the following two structs whose sizes are 8 and 1 bytes respectively: class eight { int i; char c; eight(const blub&) {} }; class one { char s; one(const blob&...
BeeOnRope's user avatar
  • 63.7k
10 votes
0 answers
206 views

Semantics of volatile std::atomic<T>

Generally std::atomic<T> does not imply semantics of volatile, i.e. operations on the atomic object are not observable side effects that the compiler needs to preserve. As a consequence the ...
user17732522's user avatar
  • 66.4k
0 votes
1 answer
53 views

How does C++ handle constexpr evaluation for non-static member function pointers on runtime objects?

The code compiles and runs, but I'm trying to understand how the expression (obj.*funcPtr)(12) can be evaluated at compile-time when obj is not declared as constexpr. I would expect that this might ...
Sami's user avatar
  • 693
-3 votes
1 answer
101 views

is there any UB in reinterpreting a standard layout struct as an unsigned char* [closed]

I wanted to see if it is safe to reinterpret_cast a Colour struct array into an unsigned char* to pass around for APIs struct Colour { unsigned char r,g,b,a; }; static_assert(sizeof(Colour) == ...
user24551355's user avatar
3 votes
1 answer
126 views

Explicit object member function with void parameter

According to cppreference since C++23 For a non-static non-virtual member function not declared with cv-qualifier or ref-qualifier, its first parameter, if not being a function parameter pack, can be ...
Fedor's user avatar
  • 19.3k

15 30 50 per page
1
2 3 4 5
431