Skip to content

sourceCpp compile error stderr cannot be caught/suppressed #1257

@andrjohns

Description

@andrjohns

When writing a try() function to check for compile errors from sourceCpp the compilation error is always printed to the console, regardless of whichever combinations of try(), suppressMessages(), suppressWarnings() or sink are used.

Reprex:

dcode <- "//[[Rcpp::export]]\n int fun(int x) { const int y; return x; }"
status <- suppressWarnings(suppressMessages(
  output <- capture.output(
    try(Rcpp::sourceCpp(code = dcode, verbose=FALSE, echo=FALSE),
                 silent = TRUE))
))

Created on 2023-03-24 with reprex v2.0.2

Standard output and standard error
fileeed07e197428.cpp:2:29: error: default initialization of an object of const type 'const int'
 int fun(int x) { const int y; return x; }
                            ^
                              = 0
1 error generated.
make: *** [fileeed07e197428.o] Error 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions