From d29eb085630aac6cbefeafe51937314ce0263593 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 12 Jan 2023 20:41:29 -0500 Subject: [PATCH] Assert on construction that `OutputsSpec::Names` is non-empty --- src/libstore/outputs-spec.hh | 9 ++++++--- src/libstore/tests/outputs-spec.cc | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libstore/outputs-spec.hh b/src/libstore/outputs-spec.hh index 82dfad479..46bc35ebc 100644 --- a/src/libstore/outputs-spec.hh +++ b/src/libstore/outputs-spec.hh @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -11,13 +12,15 @@ namespace nix { struct OutputNames : std::set { using std::set::set; - // These need to be "inherited manually" + /* These need to be "inherited manually" */ + OutputNames(const std::set & s) : std::set(s) - { } + { assert(!empty()); } + OutputNames(std::set && s) : std::set(s) - { } + { assert(!empty()); } /* This set should always be non-empty, so we delete this constructor in order make creating empty ones by mistake harder. diff --git a/src/libstore/tests/outputs-spec.cc b/src/libstore/tests/outputs-spec.cc index 5daac9234..c5e3f382b 100644 --- a/src/libstore/tests/outputs-spec.cc +++ b/src/libstore/tests/outputs-spec.cc @@ -4,6 +4,12 @@ namespace nix { +#ifndef NDEBUG +TEST(OutputsSpec, no_empty_names) { + ASSERT_DEATH(OutputsSpec::Names { std::set { } }, ""); +} +#endif + #define TEST_DONT_PARSE(NAME, STR) \ TEST(OutputsSpec, bad_ ## NAME) { \ std::optional OutputsSpecOpt = \