Questions tagged [incomplete-type]

In the C and C++ languages, an incomplete type is "lacking sufficient information to determine the size of objects of that type." (Examples: variable-length arrays, forward declarations of `struct`s, and the `void` type.)

In the C and C++ programming language, an incomplete type is

"lacking sufficient information to determine the size of objects of that type."ISO C11 standard, section 6.2.5

Examples:

The standard mentions the following three instances of incomplete types:

  1. an array type of variable, or unknown size, such as char *argv[].
  2. a type that describes an object but lacks information to determine their sizes, such as struct foo_tag;
  3. the void type (which, unlike the other two, cannot be completed)

Resources:

310 questions
11
votes
1 answer

Can I instantiate an std::reference_wrapper where T is an incomplete type?

Does std::reference_wrapper allow T to be incomplete, in the same way that a T& can be dealt with without T being complete? GCC 4.9 accepts the following: #include struct woof; struct test { test(woof& w) : w(w) {} …
Lightness Races in Orbit
  • 358,771
  • 68
  • 593
  • 989
10
votes
3 answers

How to delete all QGraphicsItem from QGraphicsScene

I've written a derived class from QGraphicsScene. At a point I need to remove all items from the scene and I want the items to be physically destroyed (destructor called). I tried the following: QList all = items(); for (int i = 0; i…
Donotalo
  • 11,954
  • 23
  • 75
  • 111
10
votes
1 answer

Can a pointer to an incomplete type be incomplete?

Can int (*)[] be an incomplete type? C 2018 6.2.5 1 says: At various points within a translation unit an object type may be incomplete (lacking sufficient information to determine the size of objects of that type) or complete (having sufficient…
Eric Postpischil
  • 141,624
  • 10
  • 138
  • 247
10
votes
1 answer

incomplete class usage with auto in template class

Is the following code well formed ? class B; template class A { B do_f() const; friend auto f(A const& a) {return a.do_f();} // #1 }; class B{}; template B A::do_f() const { return B{};} int main() { A
Jarod42
  • 173,454
  • 13
  • 146
  • 250
10
votes
3 answers

an error about C struct array in formal parameter

I have got the following code: struct student_info; void paiming1(struct student_info student[]); struct student_info { int num; char name[6]; }; The IDE gives an error error: array type has incomplete element type ‘struct…
pureZer
  • 143
  • 4
10
votes
3 answers

Handles Comparison: empty classes vs. undefined classes vs. void*

Microsoft's GDI+ defines many empty classes to be treated as handles internally. For example, (source GdiPlusGpStubs.h) //Approach 1 class GpGraphics {}; class GpBrush {}; class GpTexture : public GpBrush {}; class GpSolidFill : public GpBrush…
Nawaz
  • 327,095
  • 105
  • 629
  • 812
10
votes
3 answers

Check if type is defined

Consider this example: #include #include template struct is_defined : std::false_type { }; template struct is_defined::value && …
xinaiz
  • 6,915
  • 3
  • 26
  • 67
10
votes
1 answer

pointer to member function of incomplete type

I don't understand why adding a forward declaration for a class changes a size of its pointer to member type #include using namespace std; int main() { //struct CL; //cout<
user3514538
  • 2,294
  • 1
  • 11
  • 21
10
votes
1 answer

Why are we allowed to take the address of an incomplete type?

Consider this code: class Addressable; class Class1 { void foo(Addressable &a) { (void) &a; } }; // OK class Addressable { void *operator &() { return this; } }; class Class2 { void foo(Addressable &a) { (void) &a; } }; // Error: operator &…
user541686
  • 189,354
  • 112
  • 476
  • 821
9
votes
1 answer

What are the rules for standard library containers and incomplete types?

Given an incomplete type: struct S; Then the following declarations are: S *p; // ok, pointer to incomplete types is allowed std::deque l; // error, instantiating std::deque with incomplete type is UB But what about the following…
cigien
  • 50,328
  • 7
  • 37
  • 78
9
votes
2 answers

Static cast of reference forces template instantiation where incomplete type is fine

The following bit of code fails to compile on gcc 7.3.0 and clang 6.0.0 (but seems to compile fine under MSVC): #include struct IncompleteType; template struct Container { T value; }; using Uninstantiatable =…
Alex ten Brink
  • 879
  • 2
  • 8
  • 18
9
votes
1 answer

Extern template for template parametrized with incompete type

A compilable example: main.cpp #include "test.h" int main(int argc, char* argv[]) { auto myPtr = std::unique_ptr(getMyPtr()); } test.h #ifndef TEST_H #define TEST_H #include class MyClass; extern template class…
Smiles
  • 1,373
  • 1
  • 9
  • 12
9
votes
2 answers

Invalid use of incomplete type - why no error in this case?

I am confused about why my code is not producing the error invalid use of incomplete type, while all the reading I have done about this error suggests it should. The question stemmed from this error showing up (as expected) in the part of my code…
penelope
  • 7,605
  • 5
  • 40
  • 82
9
votes
2 answers

static assert that template typename T is NOT complete?

Is there a way to static_assert that a type T is Not complete at that point in a header? The idea is to have a compile error if someone adds #includes down the road in places they should not be. related: How to write `is_complete` template? Using…
peter karasev
  • 2,406
  • 1
  • 26
  • 37
9
votes
4 answers

C Typedef - Incomplete Type

So, out of the blue, the compiler decides to spit this in face: "field customer has incomplete type". Here's the relevant snippets of code: customer.c #include #include #include "customer.h" struct CustomerStruct; typedef…
Zyyk Savvins
  • 453
  • 2
  • 8
  • 13
1 2
3
20 21