#4918·clap

`default_value_if` with `IsPresent` doesn't ignore defaults

Author: epageCreated May 18, 2023Updated Aug 19, 2026
LabelsC-bugA-parsing

Please complete the following tasks

Rust Version

1.69

Clap Version

4.2.7

Minimal reproducible code

rust
    /// ```rust
    /// # use clap_builder as clap;
    /// # use clap::{Command, Arg, ArgAction};
    /// # use clap::builder::{ArgPredicate};
    /// let m = Command::new("prog")
    ///     .arg(Arg::new("flag")
    ///         .long("flag")
    ///         .action(ArgAction::SetTrue))
    ///     .arg(Arg::new("other")
    ///         .long("other")
    ///         .default_value_if("flag", ArgPredicate::IsPresent, Some("default")))
    ///     .get_matches_from(vec![
    ///         "prog"
    ///     ]);
    ///
    /// assert_eq!(m.get_one::<String>("other"), None);
    /// ```

Steps to reproduce the bug with the above code

Put that in the docs

Actual Behaviour

Panic

Expected Behaviour

Passes

Additional Context

Found via #4904

Holding off until clap v5 in case this is disruptive

Debug Output

No response