Open
Description
Reproducer:
// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm -verify
// RUN: %clang_cc1 -std=c++20 %t/B.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
//--- foo.hpp
#pragma once
#define FOO
//--- A.cppm
// expected-no-diagnostics
module;
#include "foo.hpp"
export module A;
//--- B.cpp
// expected-no-diagnostics
import A;
#include "foo.hpp"
#ifndef FOO
#error 'pragma once' state should not be exported on module interface
#endif
The inclusion of "foo.hpp" in B.cpp
is skipped, due to pragma once considering the inclusion from the imported A.cppm
module.
Conventional header guards work as expected.
This is due to the fact we export the HeaderSearch table in standard C++ modules. There are old workarounds for clang modules where, during search for header inclusion, we prefer a header which has been included in another module, over the normal search order. Though this causes us to merge their header infos, and that's where pragma once state lives.