incomplete-type

extern template & incomplete types

a 夏天 提交于 2021-02-08 14:19:27
问题 Recently when I was trying to optimize my include hierarchy I stumbled upon the file a.hpp : template<class T> class A { using t = typename T::a_t; }; class B; extern template class A<B>; which seems to be ill-formed. In fact it seems as if the extern template statement at the end causes an instantiation of A<B> which causes the compiler to complain about an incomplete type. My goal would have been to define A<B> in a.cpp : #include <b.hpp> template class A<B>; This way I avoid having to

incomplete type as member of std::map

流过昼夜 提交于 2021-01-28 05:06:31
问题 I came about the same issue as described here Can't allocate class with forward declared value in std::map member variable in our codebase. Hoever I also found other cases where our compiler (MSVC 2017) is able to compile this... After fiddling around with the code I found that defining the con- & destructor in the cpp allows the files to compile. In test.h : #ifndef TEST_H #define TEST_H #include <map> struct Incomplete; class Test { std::map<int, Incomplete> member; public: Test(); ~Test();

Incomplete types as function parameters and return values

99封情书 提交于 2020-04-09 15:50:36
问题 The following code compiles successfully both with clang++ 5.0.0 and g++ 7.2 (with the -std=c++17 -Wall -Wextra -Werror -pedantic-errors -O0 compilation flags): struct Foo; struct Bar { Foo get() const; void set(Foo); }; struct Foo { }; Foo Bar::get() const { return {}; } void Bar::set(Foo) { } int main() { Bar bar{}; (void)bar.get(); bar.set(Foo{}); } Is it valid to use incomplete types as function parameters and return values? What does the C++ say on it? 回答1: In a function definition , you

Incomplete types as function parameters and return values

北战南征 提交于 2020-04-09 15:49:12
问题 The following code compiles successfully both with clang++ 5.0.0 and g++ 7.2 (with the -std=c++17 -Wall -Wextra -Werror -pedantic-errors -O0 compilation flags): struct Foo; struct Bar { Foo get() const; void set(Foo); }; struct Foo { }; Foo Bar::get() const { return {}; } void Bar::set(Foo) { } int main() { Bar bar{}; (void)bar.get(); bar.set(Foo{}); } Is it valid to use incomplete types as function parameters and return values? What does the C++ say on it? 回答1: In a function definition , you

Can a pointer to an incomplete type be incomplete?

不羁岁月 提交于 2020-01-23 05:55:21
问题 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 information). Thus it seems that if the size of a type is known, the type is complete. 6.2.6.1 28 specifies that certain types of pointers must have the same sizes (pointers to void and characters, pointers to compatible types, pointers to structures,

Can a pointer to an incomplete type be incomplete?

半城伤御伤魂 提交于 2020-01-23 05:55:09
问题 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 information). Thus it seems that if the size of a type is known, the type is complete. 6.2.6.1 28 specifies that certain types of pointers must have the same sizes (pointers to void and characters, pointers to compatible types, pointers to structures,

incomplete type for std::unordered_set compiling error in g++5, compiles in clang++

我只是一个虾纸丫 提交于 2020-01-21 18:34:55
问题 Consider the code related to a previous SO question C++ cyclic dependency confusion with adjacency list representation #include <cstddef> #include <unordered_set> class Node; class Hash { public: std::size_t operator()(const Node &node) const; }; class Node { public: int data; std::unordered_set<Node, Hash> links; }; inline size_t Hash::operator()(const Node &node) const { return node.data; } int main() { } This code does not compile when using g++4.9.2 or g++5, however compiles with clang++3