https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119844
Bug ID: 119844
Summary: Incomplete types are displayed after the import module
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: printfne at gmail dot com
Target Milestone: ---
Created attachment 61148
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61148&action=edit
source code
Because of Moc, I cannot directly use import User in MainWindow.h. Therefore, I
declared the User structure in MainWindow.h and imported User in
MainWindow.cpp. I think after "import", the definition of "User" should be able
to be found. However, when using "User" in MainWindow.cpp, the compiler told me
that "User" is an incomplete type.
unzip demo.zip
cd demo
uic MainWindow.ui -o ui_MainWindow.h
demo g++15 -std=c++20 -fmodules-ts \
-I/usr/include/qt \
-I/usr/include/qt/QtWidgets \
-I/usr/include/qt/QtGui \
-I/usr/include/qt/QtCore \
-lQt5Widgets -lQt5Gui -lQt5Core \
main.cpp MainWindow.cpp User.cppm
// Here, a prompt will appear indicating that the pcm file is missing.
Therefore, execute the command again
demo g++15 -std=c++20 -fmodules-ts \
-I/usr/include/qt \
-I/usr/include/qt/QtWidgets \
-I/usr/include/qt/QtGui \
-I/usr/include/qt/QtCore \
-lQt5Widgets -lQt5Gui -lQt5Core \
main.cpp MainWindow.cpp User.cppm
Now we have obtained an error indicating that User is an incomplete type and
its member value cannot be accessed directly:
MainWindow.cpp: 在构造函数‘MainWindow::MainWindow(QWidget*)’中:
MainWindow.cpp:11:10: 错误:对不完全的类型‘using std::__shared_ptr_access<User,
__gnu_cxx::_S_atomic, false, false>::element_type = struct User’ {aka ‘struct
User’}的非法使用
11 | user_->value = 20;
| ^~
包含于文件 MainWindow.cpp:1:
MainWindow.h:13:8: 附注:forward declaration of ‘using
std::__shared_ptr_access<User, __gnu_cxx::_S_atomic, false,
false>::element_type = struct User’ {aka ‘struct User’}
13 | struct User;
| ^~~~