Index: include/clang/Basic/DiagnosticLexKinds.td =================================================================== --- include/clang/Basic/DiagnosticLexKinds.td +++ include/clang/Basic/DiagnosticLexKinds.td @@ -265,8 +265,8 @@ InGroup>; def pp_include_macros_out_of_predefines : Error< "the #__include_macros directive is only for internal use by -imacros">; -def pp_include_next_absolute_path : Warning< - "#include_next with absolute path">, +def pp_include_next_without_state : Warning< + "#include_next without previous state, searching from the beginning of the include directories list">, InGroup>; def ext_c99_whitespace_required_after_macro_name : ExtWarn< "ISO C99 requires whitespace after the macro name">, InGroup; Index: lib/Lex/HeaderSearch.cpp =================================================================== --- lib/Lex/HeaderSearch.cpp +++ lib/Lex/HeaderSearch.cpp @@ -569,11 +569,13 @@ bool SkipCache) { if (SuggestedModule) *SuggestedModule = ModuleMap::KnownHeader(); - + + // Reset CurDir for subsequent include_next searches. It needs to be done in + // both cases absolute patch and ""-include, GCC does the same. + CurDir = nullptr; + // If 'Filename' is absolute, check to see if it exists and no searching. if (llvm::sys::path::is_absolute(Filename)) { - CurDir = nullptr; - // If this was an #include_next "/absolute/file", fail. if (FromDir) return nullptr; @@ -673,8 +675,6 @@ } } - CurDir = nullptr; - // If this is a system #include, ignore the user #include locs. unsigned i = isAngled ? AngledDirIdx : 0; Index: lib/Lex/PPDirectives.cpp =================================================================== --- lib/Lex/PPDirectives.cpp +++ lib/Lex/PPDirectives.cpp @@ -1841,7 +1841,7 @@ LookupFromFile = CurPPLexer->getFileEntry(); Lookup = nullptr; } else if (!Lookup) { - Diag(IncludeNextTok, diag::pp_include_next_absolute_path); + Diag(IncludeNextTok, diag::pp_include_next_without_state); } else { // Start looking up in the next directory. ++Lookup; Index: lib/Lex/PPMacroExpansion.cpp =================================================================== --- lib/Lex/PPMacroExpansion.cpp +++ lib/Lex/PPMacroExpansion.cpp @@ -1415,7 +1415,7 @@ LookupFromFile = PP.getCurrentLexer()->getFileEntry(); Lookup = nullptr; } else if (!Lookup) { - PP.Diag(Tok, diag::pp_include_next_absolute_path); + PP.Diag(Tok, diag::pp_include_next_without_state); } else { // Start looking up in the next directory. ++Lookup; Index: test/Modules/Inputs/include_next/x/d.h =================================================================== --- /dev/null +++ test/Modules/Inputs/include_next/x/d.h @@ -0,0 +1 @@ +enum { dx = 7 }; Index: test/Modules/Inputs/include_next/y/c.h =================================================================== --- /dev/null +++ test/Modules/Inputs/include_next/y/c.h @@ -0,0 +1,2 @@ +#include "d.h" +enum { cy = 5 }; Index: test/Modules/Inputs/include_next/y/d.h =================================================================== --- /dev/null +++ test/Modules/Inputs/include_next/y/d.h @@ -0,0 +1,3 @@ +#include_next +// expected-warning@-1 {{#include_next without previous state, searching from the beginning of the include directories list}} +enum { dy = 6 }; Index: test/Modules/include_next.c =================================================================== --- test/Modules/include_next.c +++ test/Modules/include_next.c @@ -2,10 +2,14 @@ // RUN: %clang_cc1 -I%S/Inputs/include_next/x -I%S/Inputs/include_next/y -verify %s // RUN: %clang_cc1 -I%S/Inputs/include_next/x -I%S/Inputs/include_next/y -verify %s -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -// expected-no-diagnostics #include "a.h" #include "subdir/b.h" +#include + _Static_assert(ax == 1, ""); _Static_assert(ay == 2, ""); _Static_assert(bx == 3, ""); _Static_assert(by == 4, ""); +_Static_assert(cy == 5, ""); +_Static_assert(dy == 6, ""); +_Static_assert(dx == 7, "");