Skip to main content

All Questions

Best practices
2 votes
6 replies
241 views

Suppose I have a C-style matrix of elements typedef struct _RAW_DATA{ int a; int b; }RAW_DATA; inside a templated class, that defines the size of the matrix: template<size_t TDim> ...
user2281752's user avatar
8 votes
1 answer
251 views

Consider: struct A { A(); template<class T> A(T&); }; struct B { B(); B(B&); }; struct C { A a; B b; }; const C c1; C c2{c1}; All compilers agree that the ...
cpplearner's user avatar
4 votes
1 answer
174 views

The following code compiles successfully with clang and gcc. Naively, I would have expected a2 to have type std::array<std::array<int, 1>, 1>. #include <array> auto a1 = std::array{...
MarkB's user avatar
  • 2,230
1 vote
1 answer
225 views

This code gives me compiler error: "expected an expression". std::array< std::string, 3 > candidates = useOutname ? { "%O.log", "%O_.log", "_%O.log" } : { ...
PkDrew's user avatar
  • 2,301
0 votes
0 answers
58 views

The following code when compiled with -fsanitize=address emits a stack-use-after-scope error in GCC 12.3 and Clang 20.1, but not GCC 14.2. #include <functional> #include <cstdint> #include ...
MarkB's user avatar
  • 2,230
-5 votes
2 answers
375 views

I declared an array in C as: #include <stdio.h> int main() { int arr[5] = { 1, 2, 3 }; for (int i = 0; i < 5; i++) { printf("%d ", arr[i]); } return 0; } ...
Alphin Thomas's user avatar
1 vote
1 answer
82 views

In the following code I'm trying to call the constructor that takes a std::uint64_t: #include <initializer_list> #include <cstdint> template <typename T> struct MYFOO { MYFOO(...
Zebrafish's user avatar
  • 16.7k
1 vote
1 answer
136 views

I'm having some problems using aggregate initializers to initialize a POD with default member initializers. According to this article, this code snippet should work: struct Something { int x; ...
Cosmo's user avatar
  • 950
2 votes
1 answer
67 views

I'd like to be able to have an aggregate struct type that cannot be accidentally left uninitialized. Currently, with the following code: struct Foo { int a; int b; }; Foo foo; foo is left ...
Manishearth's user avatar
  • 16.4k
0 votes
1 answer
93 views

Consider the following code: #include <iostream> struct A { A(int, int) { std::cout << "A::A(int, int)\n"; } A(std::initializer_list<int>) { ...
xmllmx's user avatar
  • 44.7k
3 votes
1 answer
111 views

I would like to write a clang-tidy check that finds field declarations with copy initialization (ICIS_CopyInit) and can change them into direct list initializations (ICIS_ListInit). There is a way to ...
Benjamin Bihler's user avatar
-1 votes
1 answer
89 views

I wrote a method that populates a list with objects returned by an asynchronous method. public async Task<ObjectToReturn> GetObjectToReturnAsync() { var objectToReturn = new ObjectToReturn ...
Fabio's user avatar
  • 11
-1 votes
2 answers
188 views

Consider the following example that compiles with gcc, msvc and edg but is rejected by clang. Demo struct X { public: X(){} }; struct Y : X { }; struct Z { public: operator ...
Richard's user avatar
  • 48.8k
2 votes
2 answers
154 views

Why do seemingly all compilers reject the following program? (https://godbolt.org/z/EK8zW34nY) struct A { explicit A() {} }; int main() { A a = {}; } a should be value-initialized per [dcl....
user17732522's user avatar
  • 78.2k
3 votes
1 answer
145 views

As per the document, which states that[emphasise mine]: Missing initializers in an initializer list If an aggregate is initialized but the number of initialization values is fewer than the number of ...
John's user avatar
  • 3,574

15 30 50 per page
1
2 3 4 5
25