Skip to content

Commit a3b5a24

Browse files
authored
Merge pull request #4135 from bradlitterell/patch-1
Update compiler-warning-level-4-c4464.md
2 parents d68ca00 + 614978c commit a3b5a24

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed
Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +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 to specify your project include directories.
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

2428
```cpp
25-
#include "..\headers\C4426.h" // emits warning C4464
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+
// . . .
34+
```
2635

27-
// To fix this issue, specify only the header file name, and add
28-
// the absolute path to 'headers\' to your project's include directories
29-
#include "C4426.h"
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+
38+
```cpp
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+
// . . .
3044
```

0 commit comments

Comments
 (0)