[all-commits] [llvm/llvm-project] f50b8e: [YAML I/O] Fix bug in emission of empty sequence
Jonas Devlieghere via All-commits
all-commits at lists.llvm.org
Mon Jan 25 13:39:58 PST 2021
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: f50b8ee71faeb5056df7a950e7427f3047ff9987
https://github.com/llvm/llvm-project/commit/f50b8ee71faeb5056df7a950e7427f3047ff9987
Author: Jonas Devlieghere <jonas at devlieghere.com>
Date: 2021-01-25 (Mon, 25 Jan 2021)
Changed paths:
M llvm/include/llvm/Support/YAMLTraits.h
M llvm/lib/Support/YAMLTraits.cpp
M llvm/unittests/Support/YAMLIOTest.cpp
Log Message:
-----------
[YAML I/O] Fix bug in emission of empty sequence
Don't emit an output dash for an empty sequence. Take emitting a vector
of strings for example:
std::vector<std::string> Strings = {"foo", "bar"};
LLVM_YAML_IS_SEQUENCE_VECTOR(std::string)
yout << Strings;
This emits the following YAML document.
---
- foo
- bar
...
When the vector is empty, this generates the following result:
---
- []
...
Although this is valid YAML, it does not match what we meant to emit.
The result is a one-element sequence consisting of an empty list.
Indeed, if we were to try to read this again we get an error:
YAML:2:4: error: not a mapping
- []
The problem is the output dash before the empty list. The correct output
would be:
---
[]
...
This patch fixes that by not emitting the output dash for an empty
sequence.
Differential revision: https://reviews.llvm.org/D95280
More information about the All-commits
mailing list