Compiler warining message related to define block_operator

20 views
Skip to first unread message

Tao Jin

unread,
Mar 24, 2026, 10:27:11 PM (7 days ago) Mar 24
to deal.II User Group
Dear all,

In my dealii code hosted on the GitHub:

I have the following line of code defining a block_operator in line 5378:
const auto op_zT_wMwT_z = 
      block_operator<2, 2, BlockVector<double>>({op_uMuT, op_uMdT,
     op_dMuT, op_dMdT});

My code could compile and run as expected. However, I always get the following warning message:
"""
/home/taojin/Dropbox/dealII_Code/PhaseField/L-BFGS-B/main.cc:5378:70: warning: missing braces around initializer for ‘std::__array_traits<std::array<dealii::LinearOperator<dealii::Vector<double>, dealii::Vector<double>, dealii::internal::LinearOperatorImplementation::EmptyPayload>, 2>, 2>::_Type’ {aka ‘std::array<dealii::LinearOperator<dealii::Vector<double>, dealii::Vector<double>, dealii::internal::LinearOperatorImplementation::EmptyPayload>, 2> [2]’} [-Wmissing-braces]
 5378 |   const auto op_zT_wMwT_z = block_operator<2, 2, BlockVector<double>>({op_uMuT, op_uMdT,
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
 5379 |                op_dMuT, op_dMdT});

/home/taojin/Dropbox/dealII_Code/PhaseField/L-BFGS-B/main.cc:5378:70: warning: missing braces around initializer for ‘std::array<dealii::LinearOperator<dealii::Vector<double>, dealii::Vector<double>, dealii::internal::LinearOperatorImplementation::EmptyPayload>, 2>’ [-Wmissing-braces]
"""

I tried to place some extra curly braces but the warining message is still there.

Does anyone have any idea how to get rid of the warning message?

Thanks,

Tao

Wolfgang Bangerth

unread,
Mar 25, 2026, 12:04:28 PM (7 days ago) Mar 25
to dea...@googlegroups.com
On 3/24/26 19:27, Tao Jin wrote:
>
> I tried to place some extra curly braces but the warining message is still there.
>
> Does anyone have any idea how to get rid of the warning message?

Sometimes it takes two more levels of braces. Alternatively, look up what the
type of the constructor argument is and construct that explicitly, rather than
in-place.

Best
Wolfgang

Tao Jin

unread,
Mar 25, 2026, 3:04:00 PM (6 days ago) Mar 25
to deal.II User Group
Hi Wolfgang,

Thanks for your reply. I dug into the dealii source code and here is what I found.

Below is the instruction for the constructor
/**
 * @relatesalso BlockLinearOperator
 *
 * A variant of above function that encapsulates a given collection @p ops of
 * LinearOperators into a block structure. Here, it is assumed that Range and
 * Domain are block vectors, i.e., derived from
 * @ref BlockVectorBase.
 * The individual linear operators in @p ops must act on the underlying vector
 * type of the block vectors, i.e., on Domain::BlockType yielding a result in
 * Range::BlockType.
 *
 * The list @p ops is best passed as an initializer list. Consider for example
 * a linear operator block (acting on Vector<double>)
 * @code
 *  op_a00 | op_a01
 *         |
 *  ---------------
 *         |
 *  op_a10 | op_a11
 * @endcode
 * The corresponding block_operator invocation takes the form
 * @code
 * block_operator<2, 2, BlockVector<double>>({op_a00, op_a01, op_a10, op_a11});
 * @endcode
 *
 * @ingroup LAOperators
 */

I followed the above instruction but still got the same warning message during compilation.


On line 665 there is a TODO tag:
// TODO: Create block payload so that this can be initialized correctly

I wonder whether this is the reason for the warning message. (Sorry that my C++ skill is not good enough to fix this myself since the block_linear_operator seems to be a quite complex class).

Best,

Tao

Tao Jin

unread,
Mar 25, 2026, 9:07:48 PM (6 days ago) Mar 25
to deal.II User Group
I found the following way that makes the warning message [-Wmissing-braces] disappear.

Instead of using the instruction provided in the block_linear_operator.h
 block_operator<2, 2, BlockVector<double>>({op_a00, op_a01, op_a10, op_a11});

We can declare the block_operator the way below:
const std::array<std::array<dealii::LinearOperator<dealii::Vector<double>,

                                                   dealii::Vector<double>,
   dealii::internal::LinearOperatorImplementation::EmptyPayload>,
   2>, 2>
ops = {{
                    {{ op_uMuT, op_uMdT }},
    {{ op_dMuT, op_dMdT }}
   }};

const auto op_zT_wMwT_z = block_operator<2, 2, BlockVector<double>>(ops);

This way, the warning message will disappear during the compilation.

Best,

Tao
Reply all
Reply to author
Forward
0 new messages