[all-commits] [llvm/llvm-project] 577add: [Support/Path] Add path::is_absolute_gnu

Vinicius Tinti via All-commits all-commits at lists.llvm.org
Wed Sep 23 10:03:30 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 577adda54f075b256007ed4fa80c9988a0642a87
      https://github.com/llvm/llvm-project/commit/577adda54f075b256007ed4fa80c9988a0642a87
  Author: Vinicius Tinti <viniciustinti at gmail.com>
  Date:   2020-09-23 (Wed, 23 Sep 2020)

  Changed paths:
    M llvm/include/llvm/Support/Path.h
    M llvm/lib/Support/Path.cpp
    M llvm/unittests/Support/Path.cpp

  Log Message:
  -----------
  [Support/Path] Add path::is_absolute_gnu

Implements IS_ABSOLUTE_PATH from GNU tools.

C++17 is_absolute behavior is different the from the behavior defined by GNU
tools.

According to cppreference.com, C++17 states: "An absolute path is a path
that unambiguously identifies the location of a file without reference
to an additional starting location."

In other words, the rules are:
 1. POSIX style paths with nonempty root directory are absolute.
 2. Windows style paths with nonempty root name and root directory are
    absolute.
 3. No other paths are absolute.

GNU rules are:
 1. Paths starting with a path separator are absolute.
 2. Windows style paths are also absolute if they start with a character
    followed by ':'.
 3. No other paths are absolute.

On Windows style the path "C:\Users\Default" has "C:" as root name and "\"
as root directory.

Hence "C:" on Windows is absolute under GNU rules and not absolute under
C++17 because it has no root directory. Likewise "/" and "\" on Windows are
absolute under GNU and are not absolute under C++17 due to empty root name.

Related to PR46368.

Differential Revision: https://reviews.llvm.org/D87667




More information about the All-commits mailing list