Skip to content

Commit 614978c

Browse files
authored
Incorporate changes in rewrite
Updates for style and clarity. Also give it an Acrolinx pass.
1 parent c658907 commit 614978c

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed
Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
11
---
2-
description: "Learn more about: Compiler Warning (level 4) C4464"
2+
description: "Learn more about: Compiler Warning (level 4, off) C4464"
33
title: "Compiler Warning (level 4) C4464"
4-
ms.date: "03/13/2018"
4+
ms.date: 09/14/2022
55
f1_keywords: ["C4464"]
66
helpviewer_keywords: ["C4464"]
77
---
8-
# Compiler Warning (level 4) C4464
8+
# Compiler Warning (level 4, off) C4464
99

10-
> **relative include path contains '..'**
10+
> relative include path contains '..'
1111
12-
A `#include` directive has a path that includes a '..' parent directory specifier.
12+
A `#include` directive has a path that includes a parent directory specifier (a `..` path segment).
1313

1414
## Remarks
1515

16-
Starting in Visual Studio 2015 Update 1, the compiler can detect an include directive that contains a '..' path segment and issue a warning, if enabled. Code written in this way is usually intended to include headers that exist outside of the project by incorrectly using project-relative paths. This creates a risk that the program could be compiled by including a different source file than the programmer intends, or that these relative paths would not be portable to other build environments. Although there is no specific warning for it, we also recommend that you do not use a parent directory path segment when specifying your project include directories via the /I command-line option to the compiler; the INCLUDE environment variable; or the Project Includes settings in Visual Studio.
16+
In Visual Studio 2015 Update 1 and later versions, if enabled, the compiler can detect and issue a warning for a `#include` directive that contains a parent directory path segment (`..`). Code is sometimes written that uses parent directory relative paths to include headers from external libraries. When these parent directory-relative header paths are specified in source files, it creates a risk: The program could be compiled by including a different header file than the programmer intends. These relative paths may not be portable to other developers' build environments.
1717

18-
This warning is new in Visual Studio 2015 Update 1, and is off by default. Use [/Wall](../../build/reference/compiler-option-warning-level.md) to enable all warnings that are off by default, or __/w__*n*__4464__ to enable C4464 as a level *n* warning. For more information, see [Compiler Warnings That Are Off By Default](../../preprocessor/compiler-warnings-that-are-off-by-default.md). For information on how to disable warnings by compiler version, see [Compiler warnings by compiler version](compiler-warnings-by-compiler-version.md).
18+
Instead, we recommend you specify the paths to such headers in the build environment, such as in the `INCLUDE` environment variable or in parameters to the [`/I` (Additional include directories)](../../build/reference/i-additional-include-directories.md) compiler option. In the Visual Studio IDE, you can set the paths in your project's **Configuration Properties** > **C/C++** > **General** property page, in the **Additional Include Directories** property. Although there's no specific warning for it, we also don't recommend use of parent directory path segments when you specify your project's include directories.
19+
20+
Warning C4464 is new in Visual Studio 2015 Update 1, and is off by default. Use [`/Wall`](../../build/reference/compiler-option-warning-level.md) to enable all warnings that are off by default. Use **`/wN4464`** to enable C4464 as a level `N` warning (where `N` is 1-4). For more information, see [Compiler warnings that are off by default](../../preprocessor/compiler-warnings-that-are-off-by-default.md). For information on how to disable warnings introduced in or after a specific compiler version, see [Compiler warnings by compiler version](compiler-warnings-by-compiler-version.md).
1921

2022
## Example
2123

22-
Source code files that use '..' path segments can trigger this warning when the **/Wall** option is specified:
24+
Source code files that use `..` path segments in `#include` directives can trigger this warning when C4464 is enabled or when the **`/Wall`** option is specified.
25+
26+
In this example, the project source is in *`C:\project\source`* and an external library's header files are in *`C:\other_lib\headers`*:
2327

24-
Given this code:
2528
```cpp
26-
// proj\headers\C4426.h
27-
// ... some header contents ...
29+
// C:\project\source\C4464.cpp
30+
// Compile by using: cl /w14464 C4464.cpp
31+
#include "..\..\other_lib\headers\other.h" // C4464
32+
#include "..\..\other_lib\headers\extras\nested.h" // C4464
33+
// . . .
2834
```
35+
36+
To fix this issue, add the path *`C:\other_lib\headers`* to your project's include directories. Then, change the source to include the header files as external headers:
37+
2938
```cpp
30-
// proj\src\a.cpp
31-
#include "..\headers\C4426.h" // emits warning C4464
32-
33-
// To fix this issue, specify only the header file name, and add either
34-
// the parent path of 'headers\' (that is, proj) to your project's include directories,
35-
// or add the absolute path to the "headers" folder.
36-
// Example 1: /Ic:\proj
37-
#include "headers\C4426.h" // correct
38-
// Example 2: /Ic:\proj\headers
39-
#include "C4426.h" // also correct
39+
// C:\project\source\C4464b.cpp
40+
// Compile by using: cl /w14464 /I"C:\other_lib\headers" C4464b.cpp
41+
#include <other.h> // OK
42+
#include <extras\nested.h> // OK
43+
// . . .
4044
```

0 commit comments

Comments
 (0)